Last modified: May 23, 2026

Python Dict Append: Easy Guide

Python dictionaries are powerful. They store data in key-value pairs. Unlike lists, dictionaries do not have an append method. That confuses many beginners. But adding items is simple. You just need the right approach.

This guide explains how to "append" to a Python dict. You will learn several methods. Each method is clear and practical. By the end, you will manage dictionary data with confidence.

Why No Append for Dicts?

Lists use append to add one item at the end. Dictionaries are unordered. They use keys, not positions. So there is no "end" to append to. Instead, you assign a value to a new key. That is the closest thing to "appending".

Think of a dict like a phone book. You add a name and number. You do not add to the end. You just add the pair. The dict organizes it by the key.

Method 1: Direct Assignment

The simplest way is direct assignment. Use square brackets with a new key. Then set its value.

 
# Create a dictionary
person = {"name": "Alice", "age": 30}

# Add a new key-value pair
person["city"] = "New York"

print(person)

{'name': 'Alice', 'age': 30, 'city': 'New York'}

This works for any key. If the key exists, it updates the value. If not, it adds a new pair. This is the most common method.

Method 2: Using update Method

The update method adds multiple items at once. It takes another dict or an iterable of key-value pairs.

 
# Existing dictionary
car = {"brand": "Toyota", "model": "Corolla"}

# Add multiple items
car.update({"year": 2020, "color": "blue"})

print(car)

{'brand': 'Toyota', 'model': 'Corolla', 'year': 2020, 'color': 'blue'}

You can also pass keyword arguments. This is shorter for a few items.

 
car.update(year=2020, color="blue")

Both do the same thing. update is great for batch additions. It also merges two dictionaries into one.

Method 3: Using setdefault Method

The setdefault method adds a key only if it does not exist. It returns the value for that key. If the key is missing, it inserts the default value.

 
# Existing dictionary
student = {"name": "Bob", "grade": "A"}

# Add a key only if missing
result = student.setdefault("age", 22)

print(student)
print("Returned:", result)

{'name': 'Bob', 'grade': 'A', 'age': 22}
Returned: 22

If the key already exists, it does nothing. It just returns the current value.

 
# Key already exists
result = student.setdefault("name", "Charlie")

print(student)
print("Returned:", result)

{'name': 'Bob', 'grade': 'A', 'age': 22}
Returned: Bob

This method is useful for avoiding overwrites. It ensures you only add new items.

Method 4: Using Dictionary Unpacking

Python allows merging dicts with the ** operator. This creates a new dict. It does not modify the original.

 
# Two dictionaries
dict1 = {"a": 1, "b": 2}
dict2 = {"c": 3, "d": 4}

# Merge them
merged = {**dict1, **dict2}

print(merged)

{'a': 1, 'b': 2, 'c': 3, 'd': 4}

This is clean and readable. It works in Python 3.5 and later. If keys overlap, the later dict wins.

Method 5: Using the | Operator (Python 3.9+)

Python 3.9 introduced the merge operator |. It works like unpacking but is more intuitive.

 
# Two dictionaries
inventory = {"apples": 5, "bananas": 3}
new_items = {"oranges": 7, "grapes": 2}

# Merge using |
combined = inventory | new_items

print(combined)

{'apples': 5, 'bananas': 3, 'oranges': 7, 'grapes': 2}

You can also update in place with |=. This modifies the original dict.

 
inventory |= new_items
print(inventory)

{'apples': 5, 'bananas': 3, 'oranges': 7, 'grapes': 2}

This is the most modern way. It is clear and easy to remember.

Common Mistakes to Avoid

Beginners often try dict.append(). That raises an AttributeError. Remember: dicts have no append. Use assignment or update instead.

Another mistake is overwriting keys by accident. Always check if a key exists first. Use in operator or setdefault to be safe.

 
# Safe way to add if not exists
if "email" not in person:
    person["email"] = "[email protected]"

Real-World Example: Building a User Profile

Let's build a user profile step by step. This shows how to "append" data in practice.

 
# Start with basic info
user = {"username": "jdoe", "joined": "2024-01-15"}

# Add email
user["email"] = "[email protected]"

# Add multiple preferences
user.update({"theme": "dark", "language": "en"})

# Add settings only if missing
user.setdefault("notifications", True)

print(user)

{'username': 'jdoe', 'joined': '2024-01-15', 'email': '[email protected]', 'theme': 'dark', 'language': 'en', 'notifications': True}

This pattern is common in web apps. You start with a base dict. Then you add fields as the user provides them.

When to Use Each Method

Use direct assignment for a single new key. It is fast and simple. Use update when adding many items at once. Use setdefault to avoid overwrites. Use unpacking or the | operator for merging two dicts cleanly.

Each method has its place. Choose based on your task. For most cases, direct assignment is enough.

Performance Notes

Dictionary operations are fast. Adding a key-value pair is O(1) on average. update with many items is O(n) where n is the number of new items. For small dicts, any method works fine.

If you are working with large data, avoid frequent single additions. Use update in batches. This reduces overhead.

For more on list operations, check out our guide on Python List Operations for Beginners. It covers similar concepts for lists.

Conclusion

Python dicts do not have an append method. But adding items is easy. Use direct assignment for single items. Use update for multiple items. Use setdefault for safe adds. Use unpacking or the | operator for merging.

These methods are efficient and readable. They work for any Python version. Practice with small examples. Soon you will handle dicts like a pro.

Remember: dictionaries are key-value stores. You always add by key. That is the Python way. Happy coding!

If you want to learn more about removing items, read our article on Python List Remove by Value. It shows different removal techniques.

For advanced dict handling, explore our guide on Python List of Objects. It combines lists and dicts for complex data.