作为标题,不使用str()将unicode字符串转换为str的原因是什么?
>>> str(u'a')
'a'
>>> str(u'a').__class__
<type 'str'>
>>> u'a'.encode('utf-8')
'a'
>>> u'a'.encode('utf-8').__class__
<type 'str'>
>>> u'a'.encode().__class__
<type 'str'>
更新:感谢回答,我也不知道如果使用特殊字符创建字符串,它会自动转换为UTF-8。
>>> a = '€'
>>> a.__class__
<type 'str'>
>>> a
'\xe2\x82\xac'
在 Python 3 中,Also 是一个 Unicode 对象。