List of additions and deletions to increase the search
. append () add element to list last
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']li.append ('123') ) Print (LI)
. Insert () to insert an element at a specified location
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']li.insert (2,'the ' ) Print (LI)
. Extend () can iterate inserts, int is not iterative, each object that can iterate is added to the list as an element
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']li.extend ('123456 ') print (LI)
By deleting
. Pop () can delete the element at the specified position, delete by index, delete the last one by default, have a return
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']li.remove ('Alex' ) Print (LI)
. Remove () deletes the specified element by element
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']li.remove ('Alex' ) Print (LI)
Del li Delete list
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']del liprint (LI)
Del li[x:y] Slice Delete, you can delete the elements of the slice area
Li = ['Alex','wusir','Egon', ' Goddess ','taibai']del li[2:]print (LI)
Change
Li[x:y] = ' xxxxxx ' reassign the specified element, delete by index and delete by slice, assignment is processed iteratively, and several elements are formed by typing
Li = ['Alex','wusir','Egon', ' Goddess ','taibai'ABC ' Print (LI)
Check
For I in Li:
Print (i) all elements in the output list
Print (Li[0:2]) outputs the elements of the slice area as a list
Li = ['Alex','wusir','Egon', ' Goddess ','taibai'] for in Li: Print(i)print(Li[0:2])
Public methods
Len () calculates the length
s = (2,5,6,4,8,1,3,9,7= len (s) print (L)
Count () calculates the number of occurrences of an element
Li = ('granddarkness ')= Li.count ('a') print (s)
Index () queries the location of an element
Li = ('granddarkness ')= Li.index ('a') print (s)
Sort
. Sort () to sort numbers by size, from small to large, fastest and most efficient
Li = [5,3,7,9,1,6,4,8,2]li.sort ()print(LI)
. Sort (reverse=true) from large to small
Li = [5,3,7,9,1,6,4,8,2]li.sort (Reverse=True)print(LI)
. Reverse reverses the list element output
Li = [5,3,7,9,1,6,4,8,2]li.reverse ()print(LI)
List of nested meta-ancestors Tupe read-only list
As the name implies is a list that can only be read, its subclasses do not allow any changes, but the subclasses of the list in its subclasses may be able to change
The. Join () object is an iterative object, the return value is a string, the list is converted to a string, and all the elements in the list are stitched together
' ABCDE ' ='%'. Join (s)print(S1)
Range () outputs the number of its specified interval, which can be customized to the end and step, following the Gu Tou disregard principle
for in range (0,100,1): print(i)
The fourth day of the snow Python