When you use update like this, you are using keyword arguments, where you can pass parameters by name instead of by position in the list of arguments. The keyword in such arguments is treated as a name; the only way to have a variable keyword is to use the **kwargs syntax to pass an entire dict as a set of key=value parameters. That means that this would work . . .

update = { Var1: Var2 }
Dict.update(**update)

. . . except that keywords have to be strings, not numbers; trying to use your Var1 with value 1 as a keyword triggers a TypeError.

Because dict.update is designed for updating a dictionary, however, it also accepts an actual dictionary as an argument, without conversion to keyword arguments via **. So this does work:

Dict.update({ Var1: Var2 })

But you don't need update or its keyword arguments in your case; you can just use assignment instead:

Dict[Var1] = Var2

A couple style things: don't name variables with capital letters; that is usually an indication that a value is a constant. Also, don't use "Dict" as a variable name. Such names risk shadowing builtin functions, since functions and variables share the same namespace in Python. For example, if you assign a value to dict, you've just removed your pointer to the dict global function.

Answer from Mark Reed on Stack Overflow
🌐
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
🌐
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.
Discussions

Python: Dictionary update using variables adds new keys but replaces old values with the new one - Stack Overflow
I am trying to store information in dictionary that I want to access later. I am doing it dynamically using variables, where "badgeID" is a global counter that I am using as key and value is an array/ More on stackoverflow.com
🌐 stackoverflow.com
June 11, 2017
Updating a dictionary in python - Stack Overflow
I've been stuck on this question for quite sometime and just can't figure it out. I just want to be able to understand what I'm missing and why it's needed. What I need to do is make a function which More on stackoverflow.com
🌐 stackoverflow.com
How to update the value of a key in a dictionary in Python? - Stack Overflow
I have a dictionary which represents a book shop. The keys represent the book title and values represent the number of copies of the book present. When books are sold from the shop, the number of c... More on stackoverflow.com
🌐 stackoverflow.com
Here's a quick way to update a dictionary with a second dictionary: use the '|=' operator.
This is cool and nice to know about, but frankly DictA.update(DictB) is better IMHO. The result is exactly the same, but it’s more readable / less opaque and arcane. Even Pythonistas who have never heard of dict.update can probably guess what it does, unlike |= which you already have to be in-the-know about. dict.update is probably more backwards compatible too, though I’m less certain about this. More on reddit.com
🌐 r/learnpython
12
54
May 27, 2023
Top answer
1 of 3
6

When you use update like this, you are using keyword arguments, where you can pass parameters by name instead of by position in the list of arguments. The keyword in such arguments is treated as a name; the only way to have a variable keyword is to use the **kwargs syntax to pass an entire dict as a set of key=value parameters. That means that this would work . . .

update = { Var1: Var2 }
Dict.update(**update)

. . . except that keywords have to be strings, not numbers; trying to use your Var1 with value 1 as a keyword triggers a TypeError.

Because dict.update is designed for updating a dictionary, however, it also accepts an actual dictionary as an argument, without conversion to keyword arguments via **. So this does work:

Dict.update({ Var1: Var2 })

But you don't need update or its keyword arguments in your case; you can just use assignment instead:

Dict[Var1] = Var2

A couple style things: don't name variables with capital letters; that is usually an indication that a value is a constant. Also, don't use "Dict" as a variable name. Such names risk shadowing builtin functions, since functions and variables share the same namespace in Python. For example, if you assign a value to dict, you've just removed your pointer to the dict global function.

2 of 3
3

Just this:

Dict[var1] = var2

Calling "update" is a different thing: it can update several keys at once, and it is more usually called with another dictionary passed as positional parameter. In the form .update(par_name=value) the left part is used by the language as a "named parameter" and it is fixed in code, as a literal.

🌐
GeeksforGeeks
geeksforgeeks.org › python-variable-operations-dictionary-update
Variable Operations Dictionary Update - Python - GeeksforGeeks
January 27, 2025 - If a key already exists in the target dictionary, its value is updated with the value from the source dictionary. If the key does not exist in the target dictionary, it is ... The task of updating the values of a list of dictionaries in Python involves modifying specific keys or values within each dictionary in the list based on given criteria or conditions.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
February 16, 2026 - Example 3: In this example, keyword arguments are used instead of another dictionary. Python · d = {'p': 1} d.update(q=2, r=3) print(d) Output · {'p': 1, 'q': 2, 'r': 3} Explanation: update(q=2, r=3) adds keys using keywords. Comment · Article Tags: Article Tags: Python · python-dict · Python-dict-functions · Python Fundamentals · Introduction1 min read · Input & Output2 min read · Variables4 min read ·
🌐
Tutorialspoint
tutorialspoint.com › python › dictionary_update.htm
Python dictionary update() Method
The following example shows the usage of Python dictionary update() method. Here a dictionary 'dict' is created which consists the values: 'Zara' and '7' against the keys 'Name' and 'Age'. Then another dictionary 'dict2' is created which consist of the key 'Sex' and its corresponding value 'female'. Thereafter, using the update() method 'dict' gets updated with the items provided in 'dict2'.
Find elsewhere
🌐
AskPython
askpython.com › home › how to update a python dictionary?
How to Update a Python Dictionary? - AskPython
August 6, 2022 - The function does not return any values, rater it updates the same input dictionary with the newly associated values of the keys. ... dict = {"Python":100,"Java":150} up_dict = {"Python":500} print("Dictionary before updation:",dict) dict.update(up_dict) print("Dictionary after updation:",dict)
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python dictionary update() method
Python Dictionary update() Method -
May 31, 2024 - This code initializes a dictionary called Technology with keys 'course' and 'fee'. Then, the update() method is used to add a new key-value pair 'duration': '45days' to the dictionary. Finally, the updated dictionary is printed · # Using update() update the dictionary Technology = {'course': 'python', 'fee':4000} Technology.update({'duration':'45days'}) print("Updated Technology:\n",Technology)
🌐
Python Forum
python-forum.io › thread-43161.html
Building a dictionary .update entry from variables
September 2, 2024 - After several weeks of doing 3 passes on 40+ tutorials sticking to the path, the way the author teaches them, hoping that unresolved questions will be answered later in these tutorial(s), this pass I’m trying to answer questions raised by the tutor...
🌐
W3Schools
w3schools.com › python › python_dictionaries_change.asp
Python - Change Dictionary Items
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
🌐
Replit
replit.com › home › discover › how to update a dictionary in python
How to update a dictionary in Python | Replit
February 13, 2026 - This creates a completely new active_settings dictionary that includes the updated 'notifications' preference. This non-destructive approach is great for dynamically combining configurations without altering the original sources. Building a word frequency analyzer is a classic example where defaultdict shines, as it lets you increment counters for new words without any setup. from collections import defaultdict text = "Python is amazing Python is a great language to learn" words = text.lower().split() frequency = defaultdict(int) for word in words: frequency[word] += 1 print(dict(frequency))
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-update-dictionary-with-other-dictionary
Update Dictionary with other Dictionary - Python - GeeksforGeeks
July 12, 2025 - Explanation: a.update(b) updates dictionary a with key-value pairs from dictionary b and If a key from b already exists in a, its value is updated in a with the value from b. ... Dictionary comprehension allows for more control over the update ...
🌐
Quora
quora.com › How-do-I-update-key-and-value-in-dictionary-in-python
How to update key and value in dictionary in python - Quora
EDIT: This is called “inverting” a dictionary. You can do it by iterating through the dict, using .items() to extract each key/value pair and making the value the key, and vice versa: >>> name_to_num = { 'Bruce Lee': 36564, 'Bob Ross': 37381, 'Mary Barra': 98927 } ... You may recognize the pattern above, namely–creating an empty container and then filling it via a loop, as being the exact situation in which one should use a comprehension in Python.
🌐
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 allows you to add key-value pairs to a dictionary or merge dictionaries. It is straightforward to use and modifies the dictionary in-place. ... dict_a = {'x': 1, 'y': 2} dict_b = {'y': 3, 'z': 4} dict_a.update(dict_b) ...
🌐
W3Schools
w3schools.com › python › gloss_python_change_dictionary_item.asp
Python Change Values in a Dictionary
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