Learning python seventh day - dictionary learning method

Dictionary methods

1、pop()

The method is the same list of applications, delete the key right, and remove the key return

 

 

 

 2、copy()

Before this, I have learned, copy depth

 

 

 

 3、clear()

Clear all key-value pairs

 

 

 

 4、 fromkeys

 fromkeys () function creates a new dictionary, the sequence  seq key elements do dictionary, the dictionary initial value corresponding to all the key value is. The dictionary is somewhat similar to initialization

 

 

 

 5、get()

Somewhat similar meaning are looking for, you can view the values ​​of a key, if there is no initial value is returned

 

 

 

 6、items() 

 items () function to return may traverse the list (key, value) tuples array

 

 

7、keys()

Return word table of all linkages tuple 

 

 

 

 

 8, drink ()

Python dictionary popitem () method returns a random and delete the last pair of keys and values ​​in the dictionary.

If the dictionary is already empty, but this method is called, it is reported KeyError exception.

 

 

 

 9、setdefault()

setdefault () function and  get () method  similar, if the key does not exist in the dictionary, it will add key and value to the default value.

 

 

 

 10、update

Dictionary (Dictionary) update () function to the dictionary dict2 of key / value pairs in the update to the dict. That put another dictionary into the dictionary

 

 

 

 11、value()

Dictionary (Dictionary) values ​​() function returns all values ​​in the dictionary to the list

 

 

Guess you like

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