definitioncoding is the process of converting information from one form or format to another. Decoding, is the inverse process of coding。
character encoding (Character encoding) is a set of rules that can be used to pair a set of natural language characters (such as an alphabet or a syllable table) with a set of other things (such as a number or electrical pulse) .
Because of the physical characteristics, the computer can only recognize the high and low voltage, namely: "010100" such a binary; In order to identify human natural languages, Americans developed a set of ASCII codes in 1963. This is the first character encoding.
After the computer was introduced to China, the Chinese developed the GB2312 on the basis of ASCII, but the word count was only more than 6,000. Later, in order to develop the need, but also produced the GBK standard.
In order to unify the coding, the International Organization for Standardization (ISO) proposed the standard coding criterion: Unicode; However, due to the large space occupied by Unicode and improved on this basis, UTF-8 (8-bit UNicode transformation Format) was produced. It is a variable-length character encoding for Unicode, which can use 1~4 bytes to represent a symbol, varying the length of a byte depending on the symbol, and when the character is in the range of ASCII, it is expressed in one byte, so it is compatible with ASCII code.
Unicode is a memory-encoded representation scheme (a specification), and UTF is a scheme for how to save and transmit Unicode (implementation), which is also the difference between UTF and Unicode.
Unicode: English characters is 2 bytes, Chinese is 2 bytes
Utf-8: English characters is 1 bytes, Chinese is 3 bytes
GB2312: English characters is 1 bytes, Chinese is 2 bytes
Python2 and Python3
Py2 has two types of strings:
STR type: bytes (binary) Form stored in memory
Unicode type: unicode (binary) Form stored in memory
S1 = "Beijing" bytes type
S2 = u "Beijing" Unicode type
Repr ()
P2 Default to ASCII encoding
Py3 also has two types of strings:
STR type: stored in memory in Unicode form (binary)
Bytes Type: bytes form (binary) stored in memory
S1 = "Shanghai" uncide form Storage
S2 = b "Shanghai" bytes form storage, only the ASCII code can be recognized, this print (S2) will be error bytes can only contain ASCII literal characters.
P3 default to Utf-8 code decoding
WIN's operating system is installed with the default GBK encoding, while the Linux operating system defaults to UTF8 encoding
Python character encoding Summary