1. The default encoding of the string in the code is consistent with the encoding of the code file itself.
such as: str = ' Chinese '
If it is in a UTF8 file, the string is UTF8 encoded, and if it is in a gb2312 file, it is encoded as gb2312.
#_ *_encoding:gbk_*_
str = ' Hello '
Str.decode (' GBK ')
Str.encode (' Unicode ')
2. Python uses Unicode encoding internally. Unicode is used as an intermediate encoding in which other encoded strings are decoded (decode) into Unicode and then encoded from Unicode (encode) to another encoding.
If the string is defined like this: S=u ' Chinese '
The encoding of the string is specified as Unicode, which is the internal encoding of Python, regardless of the encoding of the code file itself.
In some Ides, the output of a string is always garbled, or even wrong, because the IDE's result output console itself cannot display the encoding of the string, rather than the problem of the program itself.
The encode of Python string and the solution to the problem of decode
Http://www.jb51.net/article/17560.htm
Python Coding issues