在列表中打印 Unicode 字符 [英] Printing Unicode Char inside a List
本文介绍了在列表中打印 Unicode 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
a = ['M\xc3\xa3e']
b = 'M\xc3\xa3e'
print a
print b
结果:
['M\xc3\xa3e']
Mãe
我如何打印 a
像:['Mãe']
推荐答案
这是python2的一个特性
This is a feature in python2
但是在 python3 中你会得到你想要的:)
But in python3 you will get what you want :).
$ 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 中你可以:
or in python2 you can:
print '[' + ','.join("'" + str(x) + "'" for x in a) + ']'
这篇关于在列表中打印 Unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文