The list in Python is similar to the variable array (ArrayList) in C # and used for sequential storage structure. Create a list sample_list = ['A', 1, ('A', 'B')] Python List Operation sample_list = ['A', 'B, 3] Get a value in the list value_start = sample_list [0] end_value = sample_list [-1] Delete the first value of the List del sample_list [0] Insert a value in the list sample_list [0: 0] = ['sample value'] Get the length of the list list_length = len (sample_list) list traversal for element in sample_list: print (element) Python list Advanced Operations/techniques generate a list of numerical increments num_inc_list = range (30) # will return a list, 2 ,..., 29] initializing the list initial_value with a fixed value = 0list_length = 5sample_list = [initial_value for I in range (10)] sample_list = [initial_value] * list_length # sample_list = [0, 0, 0, 0] Appendix: python built-in Type 1, list: list (that is, the dynamic array, the vector of the C ++ standard library, but can contain different types of elements in a list) a = ["I ", "you", "he", "she"] # The element can be of any type. Subscript: read and write by subscript. It is treated as an array and starts with 0. The first element of 0, the last element of-1, and the first element of-len are used as a negative submark, the last element of the len-1 gets the number of elements in the list len (list) # The length of the list. Actually, this method calls the _ len _ (self) method of this object. Create a continuous listL = range () # That is, L = [,], excluding the last element L = range (1, 10, 2) # That is, L = [1, 3, 5, 7, 9] list method L. append (var) # append element L. insert (index, var) L. pop (var) # Return the last element and delete it from the list. remove (var) # Delete the first element L. count (var) # The number of this element in the list. index (var) # position of the element. If no value exists, an exception is thrown. extend (list) # append list, that is, merge list to L. sort () # sort L. reverse () # reverse list OPERATOR:, +, *, keyword dela [1:] # fragment operator, used for sublist extraction [1, 2] + [3, 4] # [1, 2, 3, 3, 4]. Same as extend () [2] * 4 #: [2, 2, 2, 2] del L [1] # Delete the element del L [] # Delete the copy L1 = L # L1 is the alias of L for the element list in the specified subscript range, in C, the pointer address is the same, and the L1 operation is the L operation. The function parameter is the clone of L1 = L [:] # L1 as L, that is, another copy. List comprehension [<expr1> for k in L if <expr2>] 2. dictionary: dictionary (that is, map of c ++ standard library) dict = {'ob1 ′: 'computer ', 'ob2': 'mouse', 'ob3': 'printer'} each element is a pair, which contains two parts: key and value. Key is of the Integer or string type, and value is of any type. The key is unique, and the dictionary only recognizes the last assigned key value. The dictionary method D. get (key, 0) # Same as dict [key]. If there are multiple keys, the default value is returned. [] If no, an exception is thrown. D. has_key (key) # returns TRUE if this key exists; otherwise, FALSED. keys () # Return the dictionary Key List D. values () D. items () D. update (dict2) # Add a merged dictionary D. popitem () # obtain a pair and delete it from the dictionary. If it is null, an exception is thrown. D. clear () # clear the dictionary, same as del dictD. copy () # copy the dictionary D. cmp (dict1, dict2) # Compare the dictionary (priority is the number of elements, key size, key value size) # The first large returns 1, small returns-1, returns the same result as that of the 0dictionary replication dict1 = dict # Alias dict2 = dict. copy () # clone, that is, another copy. 3. tuple: tuples (I .e. constant arrays) tuple = ('A', 'B', 'C', 'D', 'E') can use list [],: operator to extract elements. The element cannot be directly modified. 4. string: string (that is, the list of characters that cannot be modified) str = "Hello My friend" string is an integer. It is impossible to directly modify a part of a string. But we can read a part of the string. Substring extraction str [: 6] string contains the judgment OPERATOR: in, not in "He" in str "she" not in strstring module. It also provides many methods, such as S. find (substring, [start [, end]) # searches for substrings in the specified range and returns the index value; otherwise, returns-1 s. rfind (substring, [start [, end]) # reverse lookup S. index (substring, [start [, end]) # Same as find, but the ValueError S is not found. rindex (substring, [start [, end]) # reverse lookup S. count (substring, [start [, end]) # returns the number of substring S. lowercase () S. capitalize () # uppercase S. lower () # convert to lowercase S. upper () # convert to uppercase S. swapcase () # case-insensitive For S. split (str, '') # convert string to list and split S with spaces. join (list, '') # convert list to string, and use space to connect the built-in function len (str) # string Length cmp (" my friend ", str) # string comparison. First, return 1max ('abcxyz') # Find the largest character in the string min ('abcxyz') # Find the smallest character in the string to convert oat (str) # To a floating point number, float ("1e-1") results in 0.1int (str) # converted to an integer, int ("12") results in 12int (str, base) # converted to base integer, int ("11", 2) results in 2 long (str) # variable growth integer, long (str, base) # converted to base hexadecimal long integer, string formatting (note that most escape characters, such as C language, are omitted) str_format % (parameter list)