1.clear
The clear method clears all items in the dictionary. No return value
D = {'age''name':'Gumby'} D.clear ()
>>> D
{}
2.copy
The Copy method returns a new dictionary with the same key-value pairs
D = {'age''name' 'Gumby' = d.copy ()
>>> b
{' Age ':, ' name ': ' Gumby '}
3.fromkeys
The Fromkeys method creates a new dictionary with a sequence of key values, with each key value corresponding to none by default
>>> {}.fromkeys (['name','age']) {' Age'name' : None}
4.get
The Get method is a more permissive way to access a dictionary entry, which returns none by default when accessing a key that does not exist in the dictionary.
D = {}>>>print (d.get ('name')) None
5.items
The items method returns the dictionary all items as a sequence, note: No specific order is returned
D = {'name'Gumby' age' : >>>d.items [(' age', "), ('name ' ' Gumby ')]
6.pop
The Pop method removes the key-value pair from the dictionary and returns the value of the key
D = {'a'b ': 2}>>> d.pop ('A ')1>>> d{'b' : 2}
7.update
The Update method can update another dictionary with one dictionary entry, if none is added, and if there is an update
d = { " x ": 1, " y ": 2, ' Z ": 3} b = { " x " : 0} d.update (b) >>> d{ " x " : 0, " y " : 2, Span style= "COLOR: #800000" > " z ' : 3}
8.values
The values method returns all value in the dictionary as a list
D = {'x'y'z' : 3} >>> d.values () [1, 2, 3]
From the beginning Python from novice to Professional [move]magnus Lie Hetland
Dictionary methods in Python