字节串能保存二进制数据、以及各种编码的字符串。bytes包含的字符串有可能是损坏的。

b = b'\xe4\xbd\xa0\xe5\xa5\xbd' # 你好
# s = str(b) 错误的转换方式,会转换出"b'\\xe4\\xbd\\xa0\\xe5\\xa5\\xbd'"
s = b.decode("utf-8")
 
b_ = bytes(s, encoding="utf-8")