#! -*- coding:utf-8 -*-
len() ,len(list)Method returns the number of elements in the list, list -- to calculate the number of elements in the list, return values, return the number of elements in the list
Tuples are very similar to lists. The difference is that the element values of tuples cannot be modified. Tuples are placed in brackets and lists in square brackets.
list( seq ) Method is used to convert tuples or strings to lists, return values, and return lists
#You can delete elements from the list directly by del list .
#The list pair + and * operators are similar to strings. The + sign is used for combination lists and the * sign is used for repetition lists.
Lists can be nested
Each element in a sequence is assigned a number - its location, or index, the first index is 0, the second index is 1, and so on.
list = ["name", "age", "height", "age", "1"]
list.append("333") # Add to the list at the end. This method has no return value, but it modifies the original list.
a = list.index("age") # This method returns the index location of the lookup object and throws an exception if no object is found.
b = list.count("age") # Returns the number of occurrences of characters in the list, the return value: the number of occurrences of return elements in the list
list.remove("age") # Delete the specified character. If the overlap deletion index is small, the method does not return a value but removes the first match of one of the two values.
list.insert(2, "second") # Insert data at the specified location in the list. This method does not return a value, but inserts objects at the specified location in the list.
c = list.sort() # Sort the list. If the list contains int type, it will report an error. It needs to be changed to string type.
list.reverse() # This method does not return a value, but it sorts the elements of the list in reverse order.
list.pop() # By default, delete the last one of the lists. If an index is specified, delete the string at the index location.
list.clear() # Clear the list. This method does not return a value.
d = ["1", 2, 3, 3]
f = [6, 7, 8, 9]
d.extend(f) # Function is used to append multiple values in another sequence at the end of the list at once (expanding the original list with a new list). This method does not return values, but adds new list contents to existing lists.
g = f.copy() # copy() As the name implies, duplicate a copy, the original value and the newly duplicated variable do not affect each other.
# Using = direct assignment is to refer to assignment, change one, and the other will change as well.
Link of this Article: list_test