In this guide, you will learn all about the Python dictionary update() method to update the Dictionary. In the previous tutorial, we have learned the python dictionary popitem method to delete the last inserted item from the dictionary.
To understand this example, you should have basic knowledge of the Python dictionary.
Headings of Contents
Python Dictionary update Method
The Python dictionary update method is a pre-defined dictionary method, that is used to insert the specified item into the dictionary. The specified item can be a dictionary, an iterable, or a key-value pair.
Syntax
The syntax of the python dictionary update function is:-
dictionary.update(iterable)
Parameter
The Dictionary update function in Python accepts one iterable parameter.
- iterable:- A dictionary or iterable object with key-value pairs, that will be inserted into the dictionary.
Return Value
update method in Python does not return any dictionary, it updates the existing dictionary.
Python dictionary update example
Here we will use the update method to update the existing dictionary.
Example
Details = {'first_name': 'Vishvajit', 'last_name': 'Rao', 'roll_no': 120, 'course': 'BCA'}
Details.update({'address': 'Noida'})
print(Details)
Output
{'first_name': 'Vishvajit', 'last_name': 'Rao', 'roll_no': 120, 'course': 'BCA', 'address': 'Noida'}
Conclusion
In this guide, you have seen all about the dictionary update method to insert the specified item into the dictionary.
If this article helped you, please continue visiting for further interesting python tutorials.
Other Dictionary methods
- Dictionary clear() method
- Dictionary copy() method
- Dictionary get() method
- Dictionary fromkeys() method
- Dictionary keys() method
- Dictionary pop() method
- Dictionary popitem() method
For More Information:- Click Here