Python常用类型转换实现代码实例
1.byte和str互转 b = b”example” s = “example” bytes(s, encoding = “utf8”) str(b, encoding = “utf-8”) 2.byte和int互转 b=b’\x01\x02′ num=int.from_bytes(b,’little’) b1=num.to_bytes(2,’little’) 3.byte和float互转 import struct s=b'@zQ\x16' def byteToFloat(b): return struct.unpack('!f',s)[0] def floatT
用户评论