b = b"example"
# bytes to str
str(b, encoding = "utf-8")
bytes.decode(b)
s = "example"
# str to bytes
bytes(s, encoding = "utf8")
str.encode(s)
3.x中finally之后的return不会被执行了
bytes转十六进制
s = b'\xde\xad\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\twikipedia\x03org\x00\x00\x01\x00\x01'
print(''.join(['%02x' % b for b in s]))
输出结果:dead01000001000000000000037777770977696b697065646961036f72670000010001