๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_dictionary_update.asp
Python Dictionary update() Method
Python Tuples Access Tuples Update Tuples Unpack Tuples Loop Tuples Join Tuples Tuple Methods Tuple Exercises Code Challenge Python Sets ยท Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ dict โ€บ update.html
update โ€” Python Reference (The Right Way) 0.1 documentation
Required. Either another dictionary object or an iterable of key:value pairs (iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key:value pairs.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ dictionary โ€บ update
Python Dictionary update()
update() method updates the dictionary with elements from a dictionary object or an iterable object of key/value pairs.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ dictionaries โ€บ .update()
Python | Dictionaries | .update() | Codecademy
May 13, 2025 - In Python, the .update() method adds key-value pairs from another dictionary or an iterable of key-value pairs to the target dictionary. If a key already exists, its value is updated; otherwise, a new key-value pair is added.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
October 22, 2018 - update() method in Python dictionary is used to add new key-value pairs or modify existing ones using another dictionary, iterable of pairs or keyword arguments. If a key already exists, its value is replaced.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ home โ€บ python โ€บ python dictionary update
Python dictionary update() Method
February 21, 2009 - If the key value pair is already present in the dictionary, then the existing key is changed with the new value using update() method. On the other hand if the key-value pair is not present in the dictionary, then this method inserts it.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ standard-library โ€บ dict โ€บ update
Python dict update() - Update Dictionary | Vultr Docs
November 8, 2024 - The update() method in Python dictionaries simplifies the process of modifying dictionaries by adding or updating entries. This method is versatile, allowing updates from another dictionary, iterable of pairs, or direct key-value arguments.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-dictionary-update
Python Dictionary Update
January 12, 2026 - The Python dictionary .update() method is โ€œin-place,โ€ meaning it modifies the original object directly.
Find elsewhere
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python dictionary update() method
Python Dictionary update() Method -
May 31, 2024 - Then, the update() method is used to add multiple key-value pairs (('duration','45days') and ('tutor','Richard')) from an iterable (a list of tuples) to the dictionary. Finally, the updated dictionary is printed.
Top answer
1 of 2
53

The difference is that the second method does not work:

>>> {}.update(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: update expected at most 1 arguments, got 2

dict.update() expects to find a iterable of key-value pairs, keyword arguments, or another dictionary:

Update the dictionary with the key/value pairs from other, overwriting existing keys. Return None.

update() accepts either another dictionary object or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).

map() is a built-in method that produces a sequence by applying the elements of the second (and subsequent) arguments to the first argument, which must be a callable. Unless your key object is a callable and the value object is a sequence, your first method will fail too.

Demo of a working map() application:

>>> def key(v):
...     return (v, v)
... 
>>> value = range(3)
>>> map(key, value)
[(0, 0), (1, 1), (2, 2)]
>>> product = {}
>>> product.update(map(key, value))
>>> product
{0: 0, 1: 1, 2: 2}

Here map() just produces key-value pairs, which satisfies the dict.update() expectations.

2 of 2
5
  • Python 3.9 and PEP 584 introduces the dict union, for updating one dict from another dict.
    • Dict union will return a new dict consisting of the left operand merged with the right operand, each of which must be a dict (or an instance of a dict subclass). If a key appears in both operands, the last-seen value (i.e. that from the right-hand operand) wins.
  • See SO: How do I merge two dictionaries in a single expression? for merging with the new augmented assignment version.
    • This answer.
>>> d = {'spam': 1, 'eggs': 2, 'cheese': 3}
>>> e = {'cheese': 'cheddar', 'aardvark': 'Ethel'}
>>> d | e
{'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'}
>>> e | d
{'aardvark': 'Ethel', 'spam': 1, 'eggs': 2, 'cheese': 3}
  • Additional examples from the PEP.

Motivation

The current ways to merge two dicts have several disadvantages:

dict.update

d1.update(d2) modifies d1 in-place. e = d1.copy(); e.update(d2) is not an expression and needs a temporary variable.

{**d1, **d2}

Dict unpacking looks ugly and is not easily discoverable. Few people would be able to guess what it means the first time they see it, or think of it as the "obvious way" to merge two dicts.

๐ŸŒ
Learn By Example
learnbyexample.org โ€บ python-dictionary-update-method
Python Dictionary update() Method - Learn By Example
April 20, 2020 - D1 = {'name': 'Bob', 'age': 25} ... and new entry โ€˜jobโ€™ is added. update() method accepts either another dictionary object or an iterable of key:value pairs (like tuples or other iterables of length two)....
๐ŸŒ
KDnuggets
kdnuggets.com โ€บ 2023 โ€บ 02 โ€บ update-python-dictionary.html
How to Update a Python Dictionary - KDnuggets
Learn how to update a Python dictionary using the built-in dictionary method update(). Update an existing Python dictionary with key-value pairs from another Python dictionary or iterable.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Information about dictionary update method - Python Help - Discussions on Python.org
January 16, 2024 - Hello all, I wanted to know whether the update method will always add a non existing key value pair to the end of the dictionary. Is this order guaranteed ? Thank you in advance for your help.
๐ŸŒ
Python Central
pythoncentral.io โ€บ python-dictionary-update-method-how-to-add-change-or-modify-values
Python Dictionary Update() Method: How To Add, Change, Or Modify Values | Python Central
January 29, 2024 - To use the update() function, you must use this syntax: Here, "dict" is the dictionary you want to modify or add data to. The "iterable," on the other hand, is a placeholder for any Python iterable that holds key-value pairs.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-update-dictionary
Python Update Dictionary: Methods and Usage Guide
January 30, 2024 - In this example, we have a dictionary dict1 with keys โ€˜aโ€™ and โ€˜bโ€™. We use the update() method to change the value of โ€˜bโ€™ and add a new key-value pair โ€˜cโ€™: 4. The updated dictionary now includes โ€˜aโ€™: 1, โ€˜bโ€™: 3, and โ€˜cโ€™: 4. This is a basic way to update a dictionary in Python, but thereโ€™s much more to learn about handling dictionaries.
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ using-the-python-dictionary-update-method โ€บ 0c2a1bcf87689d70361351213c5e7967
Using the Python Dictionary Update Method - Oreate AI Blog
December 22, 2025 - Syntax of the update method The syntax for the update method is as follows: dict.update(dict2) Here, 'dict' is the dictionary to be updated and 'dict2' can be another dictionary or an iterable sequence of key-value pairs to add to 'dict'.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-update-a-python-dictionary-values
How to update a Python dictionary values?
Here is the syntax of updating the values of a dictionary using either the method - dictionary[key] = new_value dictionary.update({key: new_value}) We can update a specific value in a Python dictionary by referencing the key and assigning it a new value using the assignment operator "=".