Python Dictionary Methods

Python has a set of built-in methods that you can use on dictionary.

Learn more about dictionary in Python Dictionary Tutorial.

Python Dictionary Methods
MethodDescription
clear()Removes all items from the dictionary
copy()Returns a shallow copy of the dictionary
fromkeys()Creates a new dictionary with the specified keys and values
get()Returns the value of the specified key
items()Returns a list of key:value pair
keys()Returns a list of all keys from dictionary
pop()Removes and returns single dictionary item with specified key.
popitem()Removes and returns last inserted key:value pair from the dictionary.
setdefault()Returns the value of the specified key, if present. Else, inserts the key with a specified value.
update()Updates the dictionary with the specified key:value pairs
values()Returns a list of all values from dictionary