bytes的hex和fromhex函数

bytes的hex和fromhex函数

bytes对象

hex函数:将bytes(b'x00x01x02x03x04x05')的值转换成hexstr('000102030405')

fromhex函数:将hexstr转为:bytes

十六进制字符串转bytes 就得用这个,encode 是普通字符串用的

>>> bytes([0,1,2,3,4,5]).hex()
'000102030405'
>>> bytes.fromhex('000102030405')
b'x00x01x02x03x04x05'
>>> b'abcde'.hex()
'6162636465'
>>> a = bytes.fromhex('6162636465')
>>> a
b'abcde'

原文连接:https://www.pynote.net/archives/1630

原文地址:https://www.cnblogs.com/pythonwl/p/15205595.html