Python dictionary methoden

Python heeft een set van ingebouwde methoden die op dictionaries kunnen worden gebruikt.

Method Description
clear() Remove all elements from the dictionary
copy() Return a copy of the dictionary
fromkeys() Return a dictionary with the specified key and value
get() Return the value associated with the specified key
items() Return a list of tuples containing each key-value pair
keys() Return a list containing all the keys of the dictionary
pop() Remove the element with the specified key
popitem() Remove the last inserted key-value pair
setdefault() Return the value associated with the specified key. If the key does not exist, insert a key with the specified value.
update() Update the dictionary with the specified key-value pair
values() Return a list of all values in the dictionary

In our Python Dictionary Tutorial Learn more about dictionaries in Chinese.