后浪云Python教程:python打印列表有中文乱码怎么解决?

后浪云Python教程:python打印列表有中文乱码怎么解决?插图

定义列表并直接输出,结果输出结果中文是乱码:

e=['你好',1,'apple']
print e

输出结果:

['\xe4\xbd\xa0\xe5\xa5\xbd', 1, 'apple']

解决方法:

e=['你好',1,'apple']
print json.dumps(e,encoding='utf-8',ensure_ascii=False)

输出结果:

["你好", 1, "apple"]

THE END