Python Dictionary Methods
- Previous Page Python List Methods
- Next Page Python Tuple Methods
Python has a set of built-in methods that can be used on dictionaries.
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 of the specified key |
items() | Return a list of tuples containing each key-value pair |
keys() | Return a list containing 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 of 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 pairs |
values() | Return a list of all values in the dictionary |
In our Python Dictionary Tutorial Learn more about dictionaries in Chinese.
- Previous Page Python List Methods
- Next Page Python Tuple Methods