python3 字符串和bytes互相转换
1.字符串转成bytes:str.encode('utf-8') 示例1: >>>'abc'.encode('utf-8') >>>b'abc' >>>'123abc'.encode('utf-8') >>>b'123abc' >>>'我爱python'.encode('utf-8') >>>b'\xe6\x88\x91\xe7\x88\xb1python' 2.bytes转成bytes:bytes.decode('utf-8') 示例2: >>>b'abc'.decode('utf-8') >>>abc >>>b'\xe6\x88\x91\xe7\x88\xb1python'.decode('utf-8') >>>'我爱python' 来源: CSDN 作者: whatday 链接: https://blog.csdn.net/whatday/article/details/103556787