Symptom: The Chinese in the list appears in hexadecimal after it is printed
>>> lt=[' Great god ', ' Zhzhgo ']>>> print lt[' \xb4\xf3\xc9\xf1 ', ' Zhzhgo ']>>>
First, it needs to be clear, this is not garbled, this is the Unicode string in memory form, Python output data in the command line interface, if not ASCII code, it will be output in 16 binary form.
How to make the printed results appear in Chinese? The solution is as follows:
#-*-coding:utf-8-*-lt=["Great God", ' zhzhgo ']str= ', '. Join (LT) #将列表转换为字符串print strprint type (str) lt=list (str) Print Ltprint Type (LT)
The printing results are as follows:
Great God, Zhzhgo
<type ' str ' >
[' \xe5 ', ' \xa4 ', ' \xa7 ', ' \xe7 ', ' \xa5 ', ' \x9e ', ', ', ' Z ', ' h ', ' Z ', ' h ', ' g ', ' O ']
<type ' list ' >
This article from "Today's efforts, tomorrow's success!" "Blog, be sure to keep this provenance http://zhzhgo.blog.51cto.com/10497096/1709429
A small way to output hexadecimal to Chinese when the Python list contains Chinese