Five, dictionary, (the nesting of dictionaries)

dictionary

One of the basic data types, {} stores data in the form of key-value pairs.

***

A large amount of relational data is mapped and stored in the form of key:value.

The key of the dictionary, which must be an immutable data type, is unique.

The value of the dictionary can be any data type.

 

 

***

Dictionaries are unordered until python3.5 (including 3.5).

But it is ordered after python3.6.

The query speed of the dictionary is very fast, and it stores a large amount of relational data.

How to query the dictionary:

  Through the hash algorithm, the keys of the dictionary are converted into numbers through the hash table, and the binary search is used to query the numbers.

***

Classification of data types:
mutable (unhashable): list, dict, set, 
immutable (hashable): str, tuple, int, bool 

***

Containers (3 types)

  list,dict,tuple,

Non-container (3 types)

  int,bool,set

***

Dictionary: (Add, delete, modify, search)

increase:

dic = { ' name ' : ' old boy ' , ' age ' : 56, ' hobby ' : ' women ' ,}
dic[ ' name ' ] = ' hahah '  #Responsible to replace, not responsible to add. 
print (dic) 
answer:
{'age': 56, 'hobby': 'women', 'name': 'hahah' }
dic['aaa'] = 'ccc' #Add to the end by default 
print(dic)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325208055&siteId=291194637