这里将告诉您python 对Unicode解码,具体操作方法:
打印:
print('我喜欢你'.encode('utf8'))
得到Unicode编码:
b'\u6211\u559c\u6b22\u4f60
将上面的编码赋值给str后解码:
#Unicode s1='\u6211\u559c\u6b22\u4f60' #转为utf-8(明文) print(s1.encode('utf8').decode('unicode_escape')) #转为utf-8编码 print(s1.encode('utf8').decode('unicode_escape').encode('utf8'))
输出:
我喜欢你 b'xe6x88x91xe5x96x9cxe6xacxa2xe4xbdxa0'python 对Unicode解码就为您介绍到这里,感谢您关注懒咪学编程c.lanmit.com.
本文地址:https://c.lanmit.com/bianchengkaifa/Python/1851.html