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.
Python Dictionary update Method
Python dictionary update method is a pre-defined dictionary method, that is used to insert the specified item to the dictionary. The specified item can be a dictionary, or an iterable, or a key-value pair.
Syntax
The syntax of python dictionary update function is:-
dictionary.update(iterable)
Parameter
Dictionary update function in Python accept 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 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 to the dictionary.
If this article helped you, please continue visiting for further interesting python tutorial.
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