dict.update
Add pairs from another dictionary, a sequence of pairs or keyword arguments to the dictionary.
Python 3.13
dict.update([other], **kwargs)Parameters
- otherMapping | Iterableoptional
- A dictionary or a sequence of (key, value) pairs.
- **kwargsAny
- Pairs as keyword arguments.
Return value
Nothing (None); the dictionary is changed in place.
Examples
Adding pairs from another dictionary
Python 3.13
a = {'x': 1}
a.update({'y': 2})
print(a){'x': 1, 'y': 2}Overwriting and adding with keyword arguments
Python 3.13
a = {'x': 1}
a.update(x=10, z=3)
print(a){'x': 10, 'z': 3}Details
Values of existing keys are overwritten. To get a new dictionary without changing the originals, use the | operator: a | b.
