bytes to string python hex

没有找到与「bytes to string python hex」相关的内容

AI 回答 由 glm-4-flash 生成 · 仅供参考,请自行核实
1. 将字节转换为十六进制字符串:

bytes_data = b'\x01\x02\x03'
hex_str = bytes_data.hex()
print(hex_str) # 输出:'010203'

2. 将十六进制字符串转换为字节:

hex_str = '010203'
bytes_data = bytes.fromhex(hex_str)
print(bytes_data) # 输出:b'\x01\x02\x03'
没有找到「bytes to string python hex」相关的内容

建议:检查关键词是否有错别字,或换一个更常见的说法。