You create a new key/value pair on a dictionary by assigning a value to that key

d = {'key': 'value'}
print(d)  # {'key': 'value'}

d['mynewkey'] = 'mynewvalue'

print(d)  # {'key': 'value', 'mynewkey': 'mynewvalue'}

If the key doesn't exist, it's added and points to that value. If it exists, the current value it points to is overwritten.

Answer from Paolo Bergantino on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_dictionaries_add.asp
Python - Add Dictionary Items
Python Overview Python Built-in ... Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler ...
🌐
Codecademy
codecademy.com › article › python-dictionary-append-how-to-add-items-to-dictionary
Python Dictionary Append: How to Add Items to Dictionary | Codecademy
Syntax of using a loop for adding items to a dictionary is: for key, value in some_iterable: dictionary[key] = value ... Ideal for bulk population from lists, files, APIs, etc. ... Now that you’ve seen different ways to add items to dictionaries ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary
Python Dictionary
Python · d = { "name": "Kat", ... instead of an error. New items are added to a dictionary using the assignment operator (=) by giving a new key a value....
Published   2 weeks ago
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - Dictionaries are widely used in Python for various applications such as counting occurrences, grouping data, and storing configurations. Despite their versatility, there’s no built-in add method for dictionaries.
Top answer
1 of 16
4460

You create a new key/value pair on a dictionary by assigning a value to that key

d = {'key': 'value'}
print(d)  # {'key': 'value'}

d['mynewkey'] = 'mynewvalue'

print(d)  # {'key': 'value', 'mynewkey': 'mynewvalue'}

If the key doesn't exist, it's added and points to that value. If it exists, the current value it points to is overwritten.

2 of 16
1365

I feel like consolidating info about Python dictionaries:

Creating an empty dictionary

data = {}
# OR
data = dict()

Creating a dictionary with initial values

data = {'a': 1, 'b': 2, 'c': 3}
# OR
data = dict(a=1, b=2, c=3)
# OR
data = {k: v for k, v in (('a', 1), ('b',2), ('c',3))}

Inserting/Updating a single value

data['a'] = 1  # Updates if 'a' exists, else adds 'a'
# OR
data.update({'a': 1})
# OR
data.update(dict(a=1))
# OR
data.update(a=1)

Inserting/Updating multiple values

data.update({'c':3,'d':4})  # Updates 'c' and adds 'd'

Python 3.9+:

The update operator |= now works for dictionaries:

data |= {'c':3,'d':4}

Creating a merged dictionary without modifying originals

data3 = {}
data3.update(data)  # Modifies data3, not data
data3.update(data2)  # Modifies data3, not data2

Python 3.5+:

This uses a new feature called dictionary unpacking.

data = {**data1, **data2, **data3}

Python 3.9+:

The merge operator | now works for dictionaries:

data = data1 | {'c':3,'d':4}

Deleting items in dictionary

del data[key]  # Removes specific element in a dictionary
data.pop(key)  # Removes the key & returns the value
data.clear()  # Clears entire dictionary

Check if a key is already in dictionary

key in data

Iterate through pairs in a dictionary

for key in data: # Iterates just through the keys, ignoring the values
for key, value in d.items(): # Iterates through the pairs
for key in d.keys(): # Iterates just through key, ignoring the values
for value in d.values(): # Iterates just through value, ignoring the keys

Create a dictionary from two lists

data = dict(zip(list_with_keys, list_with_values))
🌐
DataCamp
datacamp.com › tutorial › python-dictionary-append
Python Dictionary Append: How to Add Key-Value Pairs | DataCamp
August 6, 2024 - In this example, we start with dictionary_w_list where the key 'fruits' maps to a list ['apple', 'banana']. By using the .append() method, we add 'cherry' to the list. This technique is particularly useful when managing collections of items within a single dictionary. Python 3.9 introduced the merge operator (|) for combining dictionaries.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.4 documentation
When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the items() method.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-add-dictionary-items
Python - Add Dictionary Items - GeeksforGeeks
July 23, 2025 - If you want to add multiple items ... items, update() method is the most efficient way. This method accepts another dictionary or an iterable of key-value pairs and adds those pairs to the original dictionary. If any of the keys already exist, their values are updated. ... In this example, we added two new key-value pairs: 4: 40 and 5: 50...
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_ref_dictionary.asp
Python Dictionary Methods
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training
🌐
PyTutorial
pytutorial.com › python-add-to-dict-methods-and-examples
PyTutorial | Python Add to Dict: Methods and Examples
January 27, 2026 - Learn how to add items to a Python dictionary using square bracket assignment, the update() method, and merging with the | operator.
🌐
Cisco
ipcisco.com › home › python add to dictionary
Python Add To Dictionary | update() method | append() method ⋆
April 3, 2021 - In the below example, we will update the content of the dictionary with update method. device ={ "vendor": "Cisco", "model": "9000 series", "RU": 44 } device.update({"RU": 30}) print(device) The output of this python code will be like below.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-add-new-keys-to-a-dictionary
Add new keys to a dictionary in Python - GeeksforGeeks
July 11, 2025 - ... d = {"a": 1, "b": 2} # Adding a single key-value pair d.update({"c": 3}) # Adding multiple key-value pairs d.update({"d": 4, "e": 5}) print(d) ... If a key already exists then its value is updated.
🌐
SitePoint
sitepoint.com › python hub › adding items to dictionaries
Python - Adding Items to Dictionaries | SitePoint — SitePoint
Just as number += 5 adds 5 to your number, capitals |= new_capitals adds new items to your dictionary. One thing to note: just like with other methods, if there are any matching keys, the new values will replace the old ones:
🌐
Real Python
realpython.com › python-dicts
Dictionaries in Python – Real Python
3 weeks ago - The dict_items view object contains the key-value pairs of your inventory dictionary as two-item tuples of the form (key, value). ... Python’s built-in dict data type also has methods for adding and updating key-value pairs. For this purpose, you have the .setdefault() and .update() methods.
🌐
W3Schools
w3schools.com › python › python_dictionaries.asp
Python Dictionaries
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training
🌐
Guru99
guru99.com › home › python › python dictionary append: how to add key/value pair
Python Dictionary Append: How to Add Key/Value Pair
August 13, 2025 - The pop() method returns the element removed for the given key, and if the given key is not present, it will return the defaultvalue. If the defaultvalue is not given and the key is not present in the dictionary, it will throw an error. Here is a working example that shows using of dict.pop() to delete an element.
🌐
W3Schools
w3schools.com › python › gloss_python_dictionary_add_item.asp
Python Adding Items in a Dictionary
Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries
🌐
Tutorialspoint
tutorialspoint.com › python › python_add_dictionary_items.htm
Python - Add Dictionary Items
We can add dictionary items using the setdefault() method by specifying a key and a default value. In this example, we use the setdefault() to add the key-value pair "major": "Computer Science" to the "student" dictionary −
🌐
Programiz
programiz.com › python-programming › dictionary
Python Dictionary (With Examples)
March 26, 2024 - For example, country_capitals = { "Germany": "Berlin", "Italy": "Naples", "England": "London" } # change the value of "Italy" key to "Rome" country_capitals["Italy"] = "Rome" print(country_capitals) ... Note: We can also use the update() method to add or change dictionary items.