Python中的bytes,str,int等类型转换
生活随笔
收集整理的这篇文章主要介绍了
Python中的bytes,str,int等类型转换
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
在Python3.2中添加了int.from_bytes(bytes, byteorder, *, signed=False)
可实现不固定长度的bytes类型数据转int类型数据
1 >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True) ##signed标志是否为有符号数 2 -1024 3 >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False) 4 64512 5 >>> int.from_bytes(b'\x00\x00\x00\x14', byteorder='big', signed=True) ##byteorder标志小字节顺序还是大字节顺序 6 20 7 >>> int.from_bytes(b'\x00\x00\x00\x14', byteorder='little', signed=True) 8 335544320
转载于:https://www.cnblogs.com/linux-database/archive/2013/05/18/3086257.html
总结
以上是生活随笔为你收集整理的Python中的bytes,str,int等类型转换的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: jQuery图表开源软件
- 下一篇: 合并百度影音的离线数据 with pyt