python列表中可以用中文字吗?
发布时间:2026-03-05 22:00:53

中文可用于python列表中,当我们使用中文时,我们可以在程序的第一行添加中文#encoding=utf-八、防止乱码,或在输出时转码列表。
#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)请关注Python自学网了解更多Python知识。
