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.

CategoryDict Methods
KindBuilt-in Type Method
Python Versionall

📝 Syntax

dict.update([other])

⚙️ Parameters

other OptionalSource 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}
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏