Knowledge of the three containers

Before learning of the content: particularly complex variable = value, the programming will become. General programming language storage methods are provided a plurality of values ​​stored in python, we call it a container

 

      list file (corresponding to one kind similar: linked list implementation)

Is a list, or implement array [] is a list of definitions:

 

 Weak data type values ​​are defined by

 

 The second definition method: [] values ​​row there can be null

We can access elements in the list: the subscript (subscript re-start at 0, 2, 3)

 

 NOTE: There is a [4] in my definition of a, if you enter a [4] will get an error, it says "subscript out of range"

 

How do you know how much data a in a total of, we can use the function len

len function: returns the number of containers

 

Length of the container can be obtained

 

Traversal: one by one over again

List may be stored in any form, for loop values ​​listed in the list one by one

 

 

 

Elements: In the list, we can use the index to access elements

 

 append: represent adding new elements at the end of the list

 

 insert: add new elements expressed in a particular location

 

 clean: the empty container

remore: the element itself will be removed by elemental

index: find the location of elements in the list, if the element does not exist, an exception is thrown

reverse: reverse list

 

 sort: sort the list

copy: copy objects

extend: merge list

 

      set collection

Disorder and can not be repeated (no subscript)

add: add an element

remove: Removes the specified element

interstation: Intersection

difference:差集

union: union
      tuple tuple
      dict dictionary

Guess you like

Origin www.cnblogs.com/wananluni/p/11520965.html