The difference between Python2 and 3
In the Python3 in the Python2
Print (' ab ') means that the content () brackets are required. print ' AB ' can be added without adding.
Only range has a range and xrange (generator)
User exchange with input user exchange with Raw_input
Second, the assignment value:
Comparison values are equal.
is: the memory address is compared.
ID: The ID of the comparison is the same.
= =: Compares two values for equality.
Li1 = [A]
Li2 = Li1
Print (ID (LI1), ID (li2))
Print (Li1 is li2)
Third, small data pool
In a small data pool, the number ranges between -5---256.
L2 = 6
L3 = 6
Print (ID (L2), ID (L3)) ID is the same
L2 = 600
L3 = 600
Print (ID (L2), ID (L3)) ID is different
In the small data pool, the string: 1. Cannot have special characters, 2.s*20 or the same address, s*21 after all is two addresses.
S1 = ' a ' * 20
S2 = ' a ' * 20
Print (S1 is S2) True
S1 = ' a ' * 21
S2 = ' a ' * 21
Print (S1 is S2) False
The use of pycharm will not be allowed, it is recommended to use the terminal. Lists, dictionaries, Ganso, collections do not have this concept.
Iv. Types of bytes
1, the binary system between each encoding, it can not recognize each other, will produce garbled.
2, file storage, transmission, cannot be Unicode (because Unicode is 32 bit too large) can only be utf-8 utf-16 gbk,gb2312,asciid, etc.
For English:
STR: representation: s = ' Alex '
Encoding method: 00000001 Unicode
Bytes: representation: s = B ' Alex '
Encoding method: 00000000 Utf-8, GBK ....
For Chinese:
STR: representation: s = ' China '
Encoding method: 00000010 Unicode
Bytes: expression form: s = B ' \xe4\xb8\xad\xe5\x9b\xbd '
Encoding method: 00000010 utf-8, GBK ....
Conversion command:
Code: Encode convert str to Bytes,unicode to Utf-8 or GBK
s = ' China '
Print (S.encode (' Utf-8 '))
Print (S.encode (' GBK '))
S2 = B ' Alex '
Print (s2)
6th Day of Python Learning