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 Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ python-dictionary-append-how-to-add-items-to-dictionary
Python Dictionary Append: How to Add Items to Dictionary | Codecademy
The most direct and commonly used way to add or update items in a Python dictionary is by using square brackets ([]) with the assignment operator (=). This method allows you to assign a value to a new key or update the value of an existing key.
Top answer
1 of 16
4459

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))
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-dictionary-items
Python - Add Dictionary Items - GeeksforGeeks
July 23, 2025 - If you want to add multiple items at once or update existing 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.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_ref_dictionary.asp
Python Dictionary Methods
Python has a set of built-in methods that you can use on dictionaries. Learn more about dictionaries in our Python Dictionaries Tutorial.
Find elsewhere
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ devops and development โ€บ python: how to add items to dictionary
Python: How to Add Items to Dictionary
December 19, 2025 - The code shows the updated dictionary contents after adding a new item. The update() method adds a new element to an existing dictionary:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary
Python Dictionary - GeeksforGeeks
d = {1: 'Geeks', 2: 'For', 3: 'Geeks'} # Adding a new key-value pair d["age"] = 22 # Updating an existing value d[1] = "Python dict" print(d) Output ยท {1: 'Python dict', 2: 'For', 3: 'Geeks', 'age': 22} Dictionary items can be removed using built-in deletion methods that work on keys: del: removes an item using its key ยท
Published ย  1 week ago
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-items-to-dictionary
Python - Add Items to Dictionary - GeeksforGeeks
July 23, 2025 - It adds the new items to the dictionary or updates the values of existing keys. setdefault() method adds an item to the dictionary only if the key does not already exist.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_dictionary_add_item.asp
Python Adding Items in a Dictionary
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
๐ŸŒ
SitePoint
sitepoint.com โ€บ python hub โ€บ adding items to dictionaries
Python - Adding Items to Dictionaries | SitePoint โ€” SitePoint
It follows the same pattern as other Python operators like += for numbers. 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:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-new-keys-to-a-dictionary
Add new keys to a dictionary in Python - GeeksforGeeks
July 11, 2025 - The update() method can be use to merge dictionaries or add multiple keys and their values in one operation.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries.asp
Python Dictionaries
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_add_dictionary_items.htm
Python - Add Dictionary Items
It is part of the collections module in Python's standard library. We can add dictionary items using the collections.defaultdict() method by specifying a default factory, which determines the default value for keys that have not been set yet.
๐ŸŒ
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 keys in the dictionary are Name, Address and Age. Usingappend() methodwe canupdate the values for the keys in the dictionary.
๐ŸŒ
Cisco
ipcisco.com โ€บ home โ€บ python add to dictionary
Python Add To Dictionary | update() method | append() method โ‹†
April 3, 2021 - In this lesson, we will learn How to add a member to Python Dictionary. We will do different coding examples like Python dictionary add and python dictionary append. We can use these methods to insert a new item.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ add-to-dict-in-python
Adding to Dict in Python โ€“ How to Append to a Dictionary
February 28, 2023 - Example using the update() method to add multiple entries to a dictionary: myDict = {'a': 1, 'b': 2} new_data = {'c': 3, 'd': 4} myDict.update(new_data) print(myDict) ... Another fun thing about this method is that, we can use the update() method with an iterable of key-value pairs, such as a list of tuples. Let's see this in action. myDict = {'a': 1, 'b': 2} new_data = [('c', 3), ('d', 4)] myDict.update(new_data) print(myDict) ... In Python, a dictionary can be updated or made from scratch using the dict() constructor...
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ python dictionary append: how to add key/value pair?
Python Dictionary Append: How To Add Key/Value Pair?
October 14, 2024 - Yes, you can. When you use the update() method to append dictionary python, existing keys are updated with new values, but if there are any new keys, they are added to the dictionary without overwriting existing ones.