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
🌐
GeeksforGeeks
geeksforgeeks.org › python › add-a-keyvalue-pair-to-dictionary-in-python
Add a key value pair to Dictionary in Python - GeeksforGeeks
For example, starting with dictionary d = {'key1': 'geeks', 'key2': 'for'}, we add multiple key-value pairs at once: 'key3': 'Geeks', 'key4': 'is', 'key5': 'portal', and 'key6': 'Computer'. After the update, the dictionary becomes {'key1': 'geeks', 'key2': 'for', 'key3': 'Geeks', 'key4': 'is', 'key5': 'portal', 'key6': 'Computer'}.
Published   July 11, 2025
🌐
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
4456

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
1364

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 - Learn Python dictionary append techniques such as square bracket notation, the .update() method for bulk additions, and .setdefault() for conditional inserts.
🌐
Replit
replit.com › home › discover › how to add a key value pair to a dictionary in python
How to add a key value pair to a dictionary in Python | Replit
Bulk additions: You can add any number of key-value pairs in a single call. Updates existing keys: If a key from the new dictionary already exists in the original, its value is updated. In the example, update() seamlessly adds both the "grade" and "course" to the student dictionary.
🌐
Educative
educative.io › answers › how-to-add-items-to-a-dictionary-in-python
How to add items to a dictionary in Python
Line 3: We print the updated dictionary. Similarly, we can add many other key:value pairs in our dictionary.
🌐
Reddit
reddit.com › r/maildevnetwork › adding new keys to a python dictionary: a step-by-step guide
r/MailDevNetwork on Reddit: Adding New Keys to a Python Dictionary: A Step-by-Step Guide
April 25, 2023 - Python dictionaries are a fundamental data structure that allows you to store and retrieve data efficiently using key-value pairs. Unlike some other data structures, dictionaries do not have an .add() method for adding new keys.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › add-a-key-value-pair-to-dictionary-in-python
Add a key value pair to dictionary in Python
CountryCodeDict = {"India": 91, "UK" : 44 , "USA" : 1, "Spain" : 34} print(CountryCodeDict) CountryCodeDict.update( {'Germany' : 49} ) print(CountryCodeDict) # Adding multiple key value pairs CountryCodeDict.update( [('Austria', 43),('Russia',7)] ) print(CountryCodeDict) Running the above code gives us the following result ? {'Spain': 34, 'India': 91, 'USA': 1, 'UK': 44} {'Germany': 49, 'Spain': 34, 'India': 91, 'USA': 1, 'UK': 44} {'USA': 1, 'India': 91, 'Austria': 43, 'Germany': 49, 'UK': 44, 'Russia': 7, 'Spain': 34} We can also append elements to a dictionary by merging two dictionaries.
🌐
Sentry
sentry.io › sentry answers › python › add new keys to a dictionary in python
Add new keys to a dictionary in Python | Sentry
You can also use the dictionary comprehension and dictionary constructor together to add or update the key-value pairs: ... prices = {**prices, **{"Pear": 2, "Grapefruit": 2, "Orange": 3}} print(prices) # will print {"Apple": 2, "Orange": 3, ...
🌐
Analytics Vidhya
analyticsvidhya.com › home › 5 methods to add new keys to a dictionary in python
5 Methods to Add New Keys to a Dictionary in Python
February 7, 2025 - Several methods are available in Python to add new keys to a dictionary. Let’s explore each of these methods in detail. One of the simplest ways to add a new key-value pair to a dictionary is by using the bracket notation.
🌐
freeCodeCamp
freecodecamp.org › news › add-to-dict-in-python
Adding to Dict in Python – How to Append to a Dictionary
February 28, 2023 - ... If there is a key 'c' in the dictionary already, the value would be updated to 3. Multiple key-value pairs can be simultaneously added to a dictionary using the update() method.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python add keys to dictionary
Python Add keys to Dictionary - Spark By {Examples}
May 31, 2024 - The update() method is another commonly used approach to add new keys to a Python dictionary. This method takes a dictionary as an argument and adds the key-value pairs from that dictionary to the original dictionary.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - Deploy your Python applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus on scaling your app. ... If a key already exists in the dictionary, then the assignment operator updates, or overwrites, the value. The following example demonstrates how to create a new dictionary and then use the assignment operator = to update a value and add key-value pairs:
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-create-dictionary-and-add-key-value-pairs-dynamically
How to create dictionary and add key–value pairs dynamically? | GeeksforGeeks
Create a Nested Dictionary from Text File Using PythonBelow are the ways to Create Nested Dic ... Sometimes multiple tuples need to be stored under the same key. For example, if we want to group data points like coordinates or pairs of related values under a specific category, we can achieve this by adding multiple tuples to a single dictionary key.
Published   September 16, 2024
🌐
datagy
datagy.io › home › python posts › python: add key:value pair to dictionary
Python: Add Key:Value Pair to Dictionary • datagy
December 19, 2022 - The easiest way to add an item to a Python dictionary is simply to assign a value to a new key. Python dictionaries don’t have a method by which to append a new key:value pair.
🌐
Sanfoundry
sanfoundry.com › python-program-add-key-value-pair-dictionary
Python Program to Add a Key-Value Pair to the Dictionary - Sanfoundry
May 30, 2022 - 2. Declare a dictionary and initialize it to an empty dictionary. 3. Use the update() function to add the key-value pair to the dictionary. 4. Print the final dictionary. 5. Exit.