欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Python中的bytes,str,int等类型转换

发布时间:2025/3/15 python 42 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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等类型转换的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。