dict.update() Update with mapping
Last updated: 2026-09-22
dict.update() Update with mapping
dict.update([other]) merges other into the dict; other can be a dict, iterable of pairs, or kwargs.
| Category | Dict Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
dict.update([other])
⚙️ Parameters
| other Optional | Source of items: a dict, an iterable of pairs, or keyword arguments; optional. |
|---|
Returns:None (merges items from other into the dict in place).
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
{'a': 10, 'b': 2}
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat arguments does update() accept?
AA dict, an iterable of key-value pairs (e.g. [('a', 1)]), or keyword arguments (d.update(a=1)); all three forms are accepted.
QWhat does update() return?
AIt returns None! It modifies the dict in place, so never write d = d.update(x), which would turn d into None.
QWhat is the difference from the | merge operator?
Ad1 | d2 returns a new dict (Python 3.9+) and leaves the originals unchanged; update() modifies in place. Use | to produce a new dict and update() for in-place merging.
QWhat happens when a key already exists?
AThe old value is overwritten; new keys are added.