#创建10个字节 someData=bytes(10)
someInt=int(1024) byteData=someInt.to_bytes(4,byteorder='little',signed=True) gotInt=int.from_bytes(byteData,byteorder='little',signed=True)
import struct someFloat=float(3.14) #默认长度是4个字节 floatData=struct.pack('f',someFloat) #'f'就像是格式描述字符串 gotFloat=struct.unpack('f',floatData)
someStr='Hello' #编码 strData=someStr.encode('utf-8') #解码 gotStr=strData.decode('utf-8')