Basic operation python_ list

List:

increase:

append()

    Extend () add more elements    ## usage is a list of names . Function ()

 

delete:

pop () if there is no plus default parameter is the last element deleted if it is in accordance with the given parameters pruning index ## can not directly know what you want to deletion of the elements

The Remove () : can directly select the name you want to remove the element

 # Cycle time can not remove   

 # Because each remove one, Wang Qianmian list will move, it will change the index, so when you want to delete the list in a loop, how many more records list a list of elements to be deleted, and then delete the original list

Del list [] ## This can only use the index back

Clear () ## Clear List

 

 

 

change:

' List name ' [] = 'xxx' # to modify the contents # index slices, a slice may also modify the parameter list that follows the name of a plurality of three

 

 

Query: for variable in list name

 

A list of common operations:

Len () ## built-in function may also be usable with other strings

Count () ## Calculation example: calculating a list of a number of written   a.count (1) count function of only one parameter

 

Sort () ## default ascending    Sort ( Reverse = ture )   Reverse # in an inverted sense, can also be used directly in Example list: lst.reverse ()

 

Nested list:

I.e., there is also a list of list: Example  a = [1, sir, [ 1,2, [3]], 6] When looking for . 3 can enter the A [2] [2]   , when looking sir in r You may enter a [1] [2] # referred dimensionality reduction operation

Guess you like

Origin www.cnblogs.com/lingwc/p/11580442.html