a = ['M\xc3\xa3e']
b = 'M\xc3\xa3e'
print a
print b

结果:
['M\xc3\xa3e']
Mãe

我如何打印 a,如:['Mãe']

最佳答案

这是python2中的一个特性

但是在python3中你会得到你想要的:)。

$ python3
Python 3.3.3 (default, Nov 26 2013, 13:33:18)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = ['M\xc3\xa3e']
>>> print(a)
['Mãe']
>>>

或者在 python2 中你可以:
print '[' + ','.join("'" + str(x) + "'" for x in a) + ']'

关于python - 在列表中打印 Unicode 字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20947173/

10-13 03:32