bytes转string import codecs BYTES = b'\xab\xcd' STRING = codecs.encode(BYTES, 'hex').decode('ascii').upper() 打印STRING的值: >>> STRING 'ABCD' string转bytes STRING = 'ABCD' BYTES = bytes.fromhex(STRING) 打印BYTES的值: >>> BYTES b'\xab\xcd'