First, enumerate
Enumerate,for I in enumerate (an iterative object), returns a tuple with the contents (serial number, each element that can be iterated)
For I,j in enumerate (Can iterate object, start serial number), return serial number, iterate over each element
A ='ABC'b= {'a': 1,'b': 2} forIinchEnumerate (a):Print(i)#Output:#(0, ' a ')#(1, ' B ')#(2, ' C ') forI,jinchEnumerate (a,1): Print(I,J)#Output:#1 A#2 b#3 C
Second, memory address: ID ()
= = Compares the value, is the memory address
Small Data pool: int:-5~256
Str:1. Cannot have spaces
2. Length cannot exceed 20
3. Cannot have special characters
A =[]b= []Print(A = = B,a isb#True Falsea='ABC'b='ABC'Print(A = = B,a isb#true Truea='-6'b='-6'Print(A = = B,a isb#True False
Third, the Code
In Python3, the expression of STR is a string, the expression of bytes is B string, the actual encoding of STR is unicode,bytes encoding method is Utf-8, GBK, gb2312 ...
In Python3, the unicode:1 characters (whether Chinese, English, or numeric) are represented by 4 bytes
Utf-8: A character with a minimum of bytes, 1 bytes in English, 2 bytes in European text, 3 bytes in Asian text
GBK: English is 1 bytes, Chinese is 2 bytes
In Python3, strings exist in memory that is Unicode encoded, cannot be transferred directly or stored on the hard disk, to be converted to bytes type, Unicode to Bytes:a.endode (' encoded '), bytes to Unicode:a.decode ( ' Encoding ')
Utf-8 and GBK, gb2312 and other coding methods do not recognize, if you want to convert, first decoding (decode) into Unicode mode, and then encode (encode) into the corresponding way.
A ='ABC'b= A.encode ('Utf-8')Print(B,type (b))#b ' abc ' <class ' bytes ' >a='Hello'b= A.encode ('Utf-8')Print(B,type (b))#b ' \xe4\xbd\xa0\xe5\xa5\xbd ' <class ' bytes ' >C=B.decode ()Print(C,type (c))#Hello <class ' str ' >D = C.encode ('GBK')Print(D,type (d))#b ' \xc4\xe3\xba\xc3 ' <class ' bytes ' >
Python Learning (iv)