List,TuplesAndDictionaryIt is a collection of data elements that are organized together in a certain way and belong to the data structure.
ListAndTuplesThe main difference is that the list can be modified, and the tuples cannot be modified. It is more suitable to use tuples when the sequence cannot be modified.
List and metadata areReference stored values by number
DictionaryReference stored values by name
List of first lectures
1. List
1.1 List Initialization
Empty list: list_none = []
Initialize an empty list with a fixed length: list_none1 = [none] * 5 # An empty list with a length of 5. None is a built-in value of Python, indicating that nothing exists.
Instance:
Non-empty list: listtest = [1, 2, 3, 'A', 'B', 'C']
Listtest1 = ['Hi'] * 5
Instance:
1.2 list operations
Len: Returns the number of elements in the list.
Max: Returns the largest element in the list.
Min: Returns the smallest element in the list.
Instance:
ListFunction: converts all types of sequences to a list.
You can assign values to an element based on the index. The index must exist.
You can assign values to elements in a certain range (partition assignment). You can replace them with fragments of a sequence that is not long enough as the original sequence.
DEL: deletes an element.
Append: append a new element.
Count: count the number of times an element appears in the list.
Extend: append multiple values in another sequence at the end of the list.
Index: finds the index of the first matching item of a value from the list.
Insert: insert an object to the list.
Pop: removes an element from the list (the last one is removed by default). This method returns a value.
Remove: removes the first match for a value in the list.
Reverse: stores elements in the list in reverse order.
Sort: sorts the list in the original position and returns a null value.
Note: SortThe method has two optional parameters: Key and reverse. The key parameter is a function, and the reverse parameter is a simple boolean value of true or false.