Home >>Python Dictionary Methods >Python Dictionary update() Method

Python Dictionary update() Method

Python Dictionary update() Method

Python Dictionary update() Method is used to add the specified items to the dictionary with the elements from the another dictionary object.

Syntax:
dictionary.update(iterable)

Parameter Values

Parameter Description
iterable A dictionary or an iterable object with a list of key value pairs
Here is an example of Python Dictionary update() Method:

det = {
"name": "rohan",
"lname": "singh",
"year": 1990
}
det.update({"color": "blue"})
print(det)

Output:
{'name': 'rohan', 'lname': 'singh', 'year': 1990, 'color': 'blue'}
Example 2:

incolor = {'blue': 250, 'yellow':190, 'red':1980,'pink':150}  
print("Inventory:",incolor)  
incolor.update({'white':550})  
print("Updated color:",incolor)  
incolor.update({'white':350})  
print("Updated color:",incolor)  

Output:
color: {'blue': 250, 'yellow': 190, 'red': 1980, 'pink': 150}
Updated color: {'blue': 250, 'yellow': 190, 'red': 1980, 'pink': 150, 'white': 550}
Updated color: {'blue': 250, 'yellow': 190, 'red': 1980, 'pink': 150, 'white': 350}