小编给大家分享一下python列表中能不能用中文,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

python列表中可以使用中文,在我们使用中文时可以在程序第一行添加#encoding=utf-8来防止乱码,或在输出时对列表进行转码。

#encoding=utf-8importjsonlist_words=['你','我','他']print(list_words)print(str(list_words).decode('string_escape'))#正常显示汉字(可靠性不高,原因尚不明确)list_words_result=json.dumps(list_words,encoding='UTF-8',ensure_ascii=False)#正常显示汉字(经实验可靠性较高)print(list_words_result)

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