--- python dictionary data type, tuple, set

A list of follow-up knowledge:

   List can store a plurality of values, are ordered, immutable.

(1) a queue: FIFO

 

(2) Stack: last-out

(3) sort (): sort, if not specified, the default is in ascending order from small to large

 

(4) reverse (): reverse list

(5) clear (): Clear

 

 

Tuple

Capable of storing a plurality of elements, separated by commas between the element by element,

Element may be any type, tuples can not be modified.

The following is a tuple:

Remember to develop a habit: even if the container you create, only one element, but also to scholars separated by commas

(1) by index values: positive values ​​and negative values ​​(inverted value)

(2) slices

(3) Length

(4) members of the operation: in and not in

 

dictionary

Is capable of storing a plurality of sets key: value of the key, key is a description of the value, usually a character.

key must be immutable, but can be any type of value

Dictionary definition: l = { 'name': yanghui, 'age': 30}, between the key-value pairs separated by a comma.

Dictionary key is not repeated, to uniquely identify a piece of data

(1) by the access key value, it may be desirable to deposit

(2) When you use an assignment statement, as in the case key does not exist, it will automatically add a key-value pair

(3) members of the operation: in and not in

(4) length: count the number of key-value pairs

 

(5) Delete

 

The dictionary definition of the way:

 

 

set

The main role of relational operators and de-emphasis, if you do not use these two functions, it is not recommended that you

That define a set: s = {1,2,3,4,5}

If you want to create an empty set, it can only be used to create a keyword set.

Set may comprise a plurality of elements, and separated by commas

Collection will automatically remove duplicate elements

Important point: a set of three elements:

(A) Each element must be immutable

(B) without repeating elements

(C) are unordered

 

Intersection of the sets, set difference, and set subset, superset (with the program to present)

 

 

Guess you like

Origin www.cnblogs.com/benxiaohai---/p/11134881.html