1 encoding
When the Python interpreter loads the code in the. py file, the content is Ascill encoded by default, so there is an error in Chinese, so you need to tell the Python interpreter what code to use to execute the source code. )
ASCII code, mainly used to display modern English and other Western European languages, which can be represented at most 8 bits (one byte), that is: 2**8 = 256, so the ASCII code can only represent a maximum of 256 symbols.
Unicode (Uniform Code, universal Code, single code) is a character encoding used on a computer. Unicode is created to address the limitations of the traditional character encoding scheme, which sets a uniform and unique binary encoding for each character in each language, which specifies that characters and symbols are represented by at least 16 bits (2 bytes), i.e. 2 **16 = 65536.
UTF-8, which is compression and optimization of Unicode encoding, does not use a minimum of 2 bytes, but instead classifies all characters and symbols: the contents of the ASCII code are saved with 1 bytes, the characters in Europe are saved in 2 bytes, and the characters in East Asia are saved in 3 bytes ...
Problem: Python program is garbled under Windows terminal
The default encoding for Windows Gbk,linux is UTF-8.
Utf-8 GBK in python2.7 must first be converted to Unicode and then converted from Unicode to GBK.
Decode: Decoding
Encode: Encoding
The Python3 can be transferred directly from Utf-8 to GBK. Python3 will first convert Utf-8 to Unicode and then to GBK by Unicode. (There is no Unicode in Python3.)
Second, the life is short, I use Python "second article"