msg = "我爱北京"
print(msg)
print(msg.encode(encoding="utf-8"))#转二进制
print(msg.encode(encoding="utf-8").decode(encoding="utf-8"))#转utf-8
我爱北京
b'\xe6\x88\x91\xe7\x88\xb1\xe5\x8c\x97\xe4\xba\xac'
我爱北京
msg = "我爱北京"
print(msg)
print(msg.encode(encoding="utf-8"))#转二进制
print(msg.encode(encoding="utf-8").decode(encoding="utf-8"))#转utf-8
我爱北京
b'\xe6\x88\x91\xe7\x88\xb1\xe5\x8c\x97\xe4\xba\xac'
我爱北京
转载于:https://www.cnblogs.com/rongye/p/9903331.html