Learning python fourth day - a list of methods

1、append()

List append () to add yesterday said that the list of elements in the tail

2、clear()

A list of elements to clear, release the memory

 

 

 

 

 

 3、copy()

Literally copied, copied into a shallow vs. deep copy, Copy () method belongs to a list of a deep copy.

Deep and shallow copy copy copy from other pages:

Shallow copy

  • 1, for immutable types Number String Tuple, a shallow copy is only addressed to and will not open up new space.
  • 2, for the variable type List, Dictionary, Set, shallow copy will open up new space address (only the top level has opened up a new space, the inner layer of the element address is still the same), a shallow copy
  • 3, the shallow copy, changing the original object variable value of the element type, will also affect the copy of the object; change the original values ​​immutable object type elements, only the original type affected. (Operation of the copy of the object the original object is the same reason)

Deep copy

  • 1, a shallow copy, in addition to the top-level copy, further also a copy of subelements (essentially a recursive shallow copy)
  • 2, after the deep copy, the original and copies of all sub-elements of the object is independent of the address
  • 3, a deep copy may be a fragment expression
  • 4, the dictionary can copy a copy method dictionary

Effect of deep copy six basic types of

We were deep copy of the three kinds of variable types 3 kinds of immutable types.
It was found that almost the same and shallow copy.

In fact, It is good to understand, because of the deep shallow copy copy contrast, the emphasis is recursive, emphasized that the prime resources.
The operation of the top layer, the depth is no different copies.

 

 

 

 I simply understand ah address is shallow copy is a copy of the data

Deep copy is a copy of the data

Shallow copy of the data and data origin change will affect each other, and deep copy will not affect each other, common variable assignment belong shallow copy

4、count()

Value exists for the number of an element in the access list

 

 

 5、extend()

 extend () for list expansion, no return value.

 

 

 

 6、insert()

Yesterday learned insert () method, used to insert elements in the list

7、index()

Index used to find an element of the list, when an error does not exist. Parameters for the elements to find the starting position, to find the end position

8、pop()、remove()

Yesterday studied for use delete elements.

9、reverse()

reverse () function is used to reverse the list of elements.

 

 

 

 10、sort()

sort () function is used to sort the list of the original, if the parameter is specified using the comparison function specified comparison function.

  • key - is mainly used for the comparison element, only one parameter, the specific parameter is a function of iteration may be taken from the object, specify one of the elements in the iteration to be sorted.
  • reverse - collation, Reverse descending = True,  Reverse ascending = False (default).  

Guess you like

Origin www.cnblogs.com/xiaobai-yang/p/11616143.html