Python Dictionary Methods

Python Dictionary Methods

Python has a set of built-in methods that dictionary objects can call. All the python dictionary methods are as follow:

Methods Description
clear() The dictionary.clear() method removes all the elements from the dictionary.
copy() The dictionary.copy() method returns a copy of the specified Dictionary.
fromkeys() The dictionary.fromkeys() method returns a dictionary with the specified keys and values.
get() This method returns the value for the given key.
items() The dictionary.items() method returns a list containing a tuple for each key value pair
keys() This method returns View Object of All Keys
pop() The dictionary.pop() method removes and returns element having the specified key.
popitem() This method removes the last inserted key-value pair
setdefault() The dictionary.setdefault() method inserts Key with a Value if Key is not Present and returns the value of the specified key
update() The dictionary.update()updates the dictionary with the specified key-value pairs
values() This method returns a list of all the values in the dictionary

Example 1

Output

Example 2

Output

Example 3

Output