Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key : value pair.
In Python Dictionary, update() method updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs.
Syntax: dict.update([other])
Parameters: This method takes either a dictionary or an iterable object of key/value pairs (generally tuples) as parameters.
Returns: It doesn’t return any value but updates the Dictionary with elements from a dictionary object or an iterable object of key/value pairs.
Example #1: Update with another Dictionary.
# Python program to show working # of update() method in Dictionary # Dictionary with three items Dictionary1 = { 'A': 'Geeks', 'B': 'For', } Dictionary2 = { 'B': 'Geeks' } # Dictionary before Updation print("Original Dictionary:") print(Dictionary1) # update the value of key 'B' Dictionary1.update(Dictionary2) print("Dictionary after updation:") print(Dictionary1) |
Output:
Original Dictionary:
{'A': 'Geeks', 'B': 'For'}
Dictionary after updation:
{'A': 'Geeks', 'B': 'Geeks'}
Example #2: Update with an iterable.
# Python program to show working # of update() method in Dictionary # Dictionary with single item Dictionary1 = { 'A': 'Geeks'} # Dictionary before Updation print("Original Dictionary:") print(Dictionary1) # update the Dictionary with iterable Dictionary1.update(B = 'For', C = 'Geeks') print("Dictionary after updation:") print(Dictionary1) |
Output:
Original Dictionary:
{'A': 'Geeks'}
Dictionary after updation:
{'C': 'Geeks', 'B': 'For', 'A': 'Geeks'}
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python - Update dictionary with other dictionary
- Python program to update a dictionary with the values from a dictionary list
- Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()...)
- Python: Update Nested Dictionary
- Python | Even values update in dictionary
- Python - Variable Operations Dictionary update
- Python - Dictionary Tuple values update
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert string dictionary to dictionary
- Python | Pretty Print a dictionary with dictionary value
- Regular Dictionary vs Ordered Dictionary in Python
- Python | Dictionary initialization with common dictionary
- Python - Filter dictionary values in heterogenous dictionary
- Python - Convert Dictionary Value list to Dictionary List
- Python - Replace dictionary value from other dictionary
- Python - Append Dictionary Keys and Values ( In order ) in dictionary
- Python - Combine two dictionaries having key of the first dictionary and value of the second dictionary
- MongoDB Python | Insert and Update Data
- Python Set | update()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

