Coding Summary in Python: 1 Python uses the encoding of the program file to encode the Chinese string, so the Utf-8, GBK program's recorded Chinese is different encoding 2 can be forced to encode using Unicode encoding, using the u character str = u ' Chinese character ' 3. Utf-8 each Chinese occupies 3 bytes \xe8\x80\x834 GBK each Chinese occupies 2 bytes \xbf\xbc5 encoding Introduction
Encoding Rules
UTF-8 encoding: An English character equals one byte, one Chinese (with traditional) equals three bytes Unicode encoding: one English equals two bytes, and one Chinese (with traditional) equals two bytes.
Verification:
write 1 characters in Notepad to see the size of the file
Gbk:2 Bytes | Unicode:4 bytes | utf-8:6 bytes
Notepad write 2 Chinese characters
GBK: 4 bytes |  unicode:6 bytes Span style= "FONT-SIZE:10.5PT; line-height:1.5 ">| utf-8:9 bytes
There seems to be a problem, besides GBK, the other two encodings are completely incompatible with coding rules ... , finally, by viewing the 16-input editor ( ultraedit " View the contents of the file Discovery Notepad for Unicode, utf-8 encoding begins with a character that occupies a space for a Chinese character (2 bytes, 3 bytes
Notepad write 1 kanji to see the size of a file
gbk:2 bytes | unicode: 2 | &NBSP, utf-8: 3 byte
Notepad write 2 Chinese characters
GBK: 4 bytes |  unicode:4 byte | utf-8: 6
remark:
1If you want to get Chinese encoding, you can use Str.encode (' hex ')
str = "Test" <span style= "White-space:pre" ></span>for item in str: <span style= "White-space:pre" > </span>print item.encode ("hex") #每个汉子 use 3 bytes
2 bytes (byte): 8-bit (bit)
Code Summary in Python: