dict.update
Add pairs from another dictionary, a sequence of pairs or keyword arguments to the dictionary.
Python 3.13
dict.update([other], **kwargs)- [ ]optional part
- other
- A dictionary or a sequence of (key, value) pairs.Mapping | IterableOptional
- **kwargs
- Pairs as keyword arguments.Any
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.
