Python list
The list is the most frequently used data type in Python.
A list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, and strings that can even contain lists (that is, nesting).
The list is identified by [], which is the most common type of composite data for Python.
The cut of the value in the list can also be used to the variable [head subscript: Tail subscript], you can intercept the corresponding list, from left to right index default 0, starting from right to left index default-1, subscript can be empty to take the head or tail.
Inline Functions
Example Analysis:
1. Add a new object at the end of the list
li=[One,one,one,'aa','bb',' cc'] li.append ('dd') print (LI)
2. Insert an element before the specified index position
li=[One,one,one,'aa','bb',' cc']li.insert (3,'+ ') Print (LI)
3. Deleting an element
li=[One,one,one,'aa','bb',' cc'] del li[5]print (LI)
4. Popup Elements
li=[ One, A, -,'AA','BB','cc'] Li.pop () #默认是栈顶元素print (LI) Li=[ One, A, -,'AA','BB','cc'] Li.pop (0) #指定元素值print (LI)
5. Delete the value element (without knowing the location, but knowing the value)
li=[One,one,one,'aa','bb',' cc']li.remove ('cc') print (LI)
6. Permanent sorting by letter
li=[, and]li. Sort () #永久排序print (li) Li=[,]sorted (LI) # Temporary sort print (LI)
7. List reversal
li=[,]li.reverse () #反向列表永久print (LI) Li=[one by One, ]list,reversed (li) #反向列表暂时print (Li )
8. Return the list length
li=[,]len (li)
9. Clear the list
li=[, and]li. Clear () print (LI)
10. Copy the list
li=[,]ri=li.copy () print (RI)
11. Returns the number of specified elements in the list
li=[One,one, one,one]li.count (one)
12. Append sequence B at the end of the list
li=[,]b=['aa', ' BB ' ]li.extend (B) print (RI)
13. Returns the first position of a specified element in a list
li=[One,one, one,one]li.index (one)
14. Specify whether the element returns a bool value in the list
li=[One,one,one,one, one in litrue
Python List of list-