One, the type of code:
1 Acsic code basic without different coding between the interoperability will produce garbled,
2unicode a letter 4 bytes 00000000 00000000 00100100 01000000
Chinese 4 bytes 00000000 00000000 00100100 00000000
3utf-8 Chinese A letter 1 byte 00000001
Europe 2 Bytes 00000000 00000000 00100100 00000000
Asian Chinese 3 Bytes 00000000 00000000 00000000 00100100 00000000
4 gbk A letter 2 Bytes 00000000 00001000
Chinese Asian 2 bytes 00100100 00000000
Two: The difference between byte (bytes) and string (str):
Bytes: representation: s = ' Q ' b1 = S.encode (' utf-8 ') print (B1) B1 = B ' Q '
Internal storage is (Utf-8, GBK, gb232, etc.)
s1 = ' Xiao Mei '
B11 = S1.encode (' utf-8 ')
Representation: s = B ' \xe6\x99\x93\xe6\xa2\x85 ' (utf-8,gbk,gb2312 ... ) 010101
0000 1000 0000 0000 0000 0001 0000 1001 0000 0000 0000 0001
Note: In the case of Utf-8 B there are 6 (E6 99, etc.) said the name of Xiao Mei is Chinese utf-8 is two words 6 bytes
S2 = ' Xiao Mei '
B22 = S1.encode(' GBK ')
Print (B22)
B ' \xcf\xfe\xc3\xb7 '
Representation: s = B ' \xcf\xfe\xc3\xb7 ' (utf-8,gbk,gb2312 ... ) 010101
0000 1000 0000 0000 0000 0001 0000 1001
Note: In the case of GBK B there are 4 (cf XF, etc.) said the name of Xiao Mei is Chinese GGBK is two words 4 bytes
Str The representation of s = "Wangyan ' internal storage is (Unicode)
ID (memory address) = = is the value of the comparison
List Dictionary meta-ancestor set memory address is not the same
Small Data pool for int
int: Range: -5---The same number created by the first, pointing to the same memory address. Except spaces
STR: Strings generally point to the memory address you want to have, except for spaces.
s = ' Alex '
Print (S,type (s))
Print (S,type (s), ID (s)) Alex <class ' str ' > 51749664
if S1 = S2 = ' Wangyan '
Print (S1 = s2)
Print (S1 is S2)
Small Data pool for int
int: Range: -5---The same number created by the first, pointing to the same memory address.
Python Basics About Encoding