在 Python 3 中,我们使用 "string".encode()
和 "string".decode()
将 Unicode 字符串转换为字节字符串,或者转换一个字节字符串到一个 Unicode 字符串。
在Python 2中,我们有str()
和unicode()
,我们可以encode()
和decode()
也给他们。但是,Python 3 之间有什么区别吗?
最佳答案
在python2中,str是字节串,unicode是unicode字符串。但是编码和解码有些傻事,详情引用http://nedbatchelder.com/text/unipain.html
关于python - Python 2/3 中的编码/解码有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15335052/