当前位置: 首页 > 图灵资讯 > 行业资讯> python列表无法显示汉字怎么解决?

python列表无法显示汉字怎么解决?

来源:图灵python
时间: 2026-01-12 17:23:17

python列表中不能正常显示汉字的解决方案:

#encoding=utf-8

importjson

list_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)

json.dumps()将dict类型的数据转换为str。

请关注Python自学网了解更多Python知识。