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
🌐
W3Schools
w3schools.com › python › python_dictionaries_add.asp
Python - Add Dictionary Items
Python Examples Python Compiler ... = "red" print(thisdict) Try it Yourself » · The update() method will update the dictionary with the items from a given argument....
🌐
W3Schools
w3schools.com › python › python_dictionaries.asp
Python Dictionaries
In Python 3.6 and earlier, dictionaries are unordered. Dictionaries are written with curly brackets, and have keys and values: ... Dictionary items are ordered, changeable, and do not allow duplicates. Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
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.
🌐
TutorialsPoint
tutorialspoint.com › add-a-key-value-pair-to-dictionary-in-python
Add a key value pair to dictionary in Python
CountryCodeDict = {"India": 91, ... 1, 'UK': 44} After adding {'Spain': 34, 'India': 91, 'USA': 1, 'UK': 44} The update() method directly takes a key-value pair and puts it into the existing dictionary....
🌐
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.
🌐
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 - This article will explore various methods to add new keys to a dictionary in Python and discuss some best practices to follow. ... Learn the fundamentals of key-value pairs in Python dictionaries and their role in efficiently storing and retrieving data.
Find elsewhere
🌐
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 - We can make use of the built-in function append() to add elements to the keys in the dictionary.
🌐
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
Learn how to add key-value pairs to a Python dictionary. This guide covers different methods, tips, real-world uses, and common error fixes.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - The following example demonstrates how to to create two dictionaries and use the merge operator to create a new dictionary that contains the key-value pairs from both: site = {'Website':'DigitalOcean', 'Tutorial':'How To Add to a Python Dictionary', 'Author':'Sammy'} guests = {'Guest1':'Dino Sammy', 'Guest2':'Xray Sammy'}
🌐
Stack Abuse
stackabuse.com › python-how-to-add-keys-to-dictionary
Python: How to Add Keys to a Dictionary
March 8, 2023 - The quickest way to add a single item to a dictionary is by using a dictionary's index with a new key and assigning a value. For example, we add a new key-value pair like this: ... Python allows adding multiple items to dictionaries as well.
🌐
datagy
datagy.io › home › python posts › python: add key:value pair to dictionary
Python: Add Key:Value Pair to Dictionary • datagy
December 19, 2022 - In this tutorial, you’ll learn how to add key:value pairs to Python dictionaries. You’ll learn how to do this by adding completely new items to a dictionary, adding values to existing keys, and dictionary items in a for loop, and using the zip() function to add items from multiple lists.
🌐
Reddit
reddit.com › r/learnpython › how do you add to a value in a dictionary?
r/learnpython on Reddit: How do you add to a value in a dictionary?
October 14, 2021 -

I know how to update values in a dictionary. That's easy, and there are multiple ways to do it. However, what I'm looking for is how to add to a value in a dictionary. For example:

    def frequency_dictionary(words):
      new_dict = {}
      for word in words:
        if word not in new_dict:
          new_dict[word] = 1
        else:
           #?????
      return new_dict

I want this function to add 1 to the value of a word for each time it is featured in the words list. For example, print(frequency_dictionary(["apple", "apple", "cat", 1])) should return {"apple":2, "cat":1, 1:1}. The comment in the function with question marks is the part I am stuck on. What are some options to do this?

I tried looking this up, but all I got was info on how to update values, not add to them.

🌐
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 - Python dictionary append is simply used to add a key/value to the existing dictionary. The dictionary objects are mutable.
🌐
Sentry
sentry.io › sentry answers › python › add new keys to a dictionary in python
Add new keys to a dictionary in Python | Sentry
The simplest way is to assign a value to a new key using Python’s indexing/square brackets syntax: ... prices = {"Apple": 1, "Orange": 2} # existing dictionary prices["Avocado"] = 3 # new key-value pair print(prices) # will print {"Apple": 1, "Orange": 2, "Avocado": 3}
🌐
Real Python
realpython.com › videos › add-key-value-pairs-solution
Add Key-Value Pairs (Solution) (Video) – Real Python
To add a key-value pair to your dictionary, use the square bracket notation. If you want to add Enterprise as a key and Picard as the value, you write captains and then an opening square bracket, and then inside of quotes, the name of the ship…
Published   March 12, 2024
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python add keys to dictionary
Python Add keys to Dictionary - Spark By {Examples}
May 31, 2024 - Dictionaries are data type in python, that allows you to store key-value pairs. To add keys to the dictionary in Python, you can use the square bracket notation, the update() method, the dict.setdefault() method, and dictionary unpacking.
🌐
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.