小编给大家分享一下python打印列表有中文乱码的解决方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨方法吧!

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

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

输出结果:

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

解决方法:

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

输出结果:

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

看完了这篇文章,相信你对python打印列表有中文乱码的解决方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!