My Python self-learning Path 2: List learning, python self-learning path list
I learned the path of Python by myself, and we started to learn the list in a rough way.
List is the most basic data structure in Python and the most common data type.
1. Create a list:
2. Common List operations: indexing, slicing, adding, and deleting.
(1) index: the value in the index access list can be used.
(2) Slice: truncates values in the list.
Tip: The Slice index of the list starts from 0. I understand it:
List [] outputs 2 and 3.
(3) Add: add data to the list.
List. append (obj) is added to the end of the list.
List. extend (seq) append multiple values in another sequence at a time at the end of the list (extend the original list with the new list)
(4) Delete: list. pop (obj) removes a data entry at the end of the list. obj is the index position of the list. List. remove (obj) removes the first matched value. obj is a value.
Pop ():
Remove ():
3. List common methods.
List. extend ()
List. index (obj), obj is the element in the list, list. index (obj) gets the index position of obj.
List. insert (index, obj), insert an element at the index position
List. reverse () elements in the reverse list
List. sort () sorts the original list
List. len () Get the list Length
Cmp (list1, list2) compares two list elements
List + list1 is equivalent to list. extend (list1)
List * 2
Max (list): returns the maximum value of the list element.
Min (list): returns the minimum value of the list element.
List (seq): convert a tuple to a list.
The methods I know mainly focus on these aspects. If you have any shortcomings, I hope you can understand them.