dict.update()

dict.update([other])
Returns: None · Updated March 13, 2026 · Dict Methods
dictionaries methods mutation

The .update() method updates the dictionary with key-value pairs from another dictionary or from an iterable of key-value pairs. It modifies the dictionary in place and returns None.

Syntax

dict.update([other])

Parameters

ParameterTypeDefaultDescription
othermapping or iterableRequiredA dictionary or an iterable of key-value pairs (like tuples) to merge into the dictionary

Return Value

Returns None. The dictionary is modified in place.

Examples

Basic usage - merging two dictionaries

Update a dictionary with another dictionary:

config = {"host": "localhost", "port": 8080}
defaults = {"port": 3000, "timeout": 30}

config.update(defaults)

print(config)
# {host: localhost, port: 3000, timeout: 30}

Note: The original config dictionary is modified, and values from defaults overwrite matching keys.

Using keyword arguments

You can also update using keyword arguments:

user = {"username": "alice"}

user.update(email="alice@example.com", active=True)

print(user)
# {username: alice, email: alice@example.com, active: True}

Combining both approaches

Mix a dictionary with keyword arguments:

settings = {"debug": False}

settings.update({"log_level": "info"}, verbose=True)

print(settings)
# {debug: False, log_level: info, verbose: True}

Updating with an iterable of tuples

Pass any iterable of key-value pairs:

data = {"a": 1}

pairs = [("b", 2), ("c", 3)]
data.update(pairs)

print(data)
# {a: 1, b: 2, c: 3}

Using with zip

Common pattern: combine two lists into a dictionary:

keys = ["name", "age", "city"]
values = ["Bob", 25, "Chicago"]

user = {}
user.update(zip(keys, values))

print(user)
# {name: Bob, age: 25, city: Chicago}

Practical example - updating config with user overrides

default_config = {
    "host": "0.0.0.0",
    "port": 8000,
    "workers": 4,
    "debug": False
}

# User provides only what they want to override
user_overrides = {
    "port": 9000,
    "debug": True
}

default_config.update(user_overrides)

print(default_config)
# {host: 0.0.0.0, port: 9000, workers: 4, debug: True}

Merging multiple dictionaries

Python 3.9+ supports the merge operator (|), but update() can still merge multiple dicts:

base = {"theme": "light"}

# Sequential updates
base.update({"font": "sans-serif"})
base.update({"font_size": 14})

print(base)
# {theme: light, font: sans-serif, font_size: 14}

Handling non-dict mappings

Works with any mapping-like object:

from collections import OrderedDict

original = {"a": 1}
updates = OrderedDict([("b", 2), ("c", 3)])

original.update(updates)

print(original)
# {a: 1, b: 2, c: 3}

Common Patterns

Configuration with defaults

def load_config(overrides=None):
    config = {
        "database": "sqlite://data.db",
        "cache_ttl": 3600,
        "max_connections": 10
    }
    
    if overrides:
        config.update(overrides)
    
    return config

# Use defaults
print(load_config())
# {database: sqlite://data.db, cache_ttl: 3600, max_connections: 10}

# Override some values
print(load_config({"database": "postgres://prod"}))
# {database: postgres://prod, cache_ttl: 3600, max_connections: 10}

Collecting data into a dictionary

def add_items(tracker, items):
    for item in items:
        tracker.update(item)

tracker = {}
add_items(tracker, [{"name": "apple"}, {"color": "red"}, {"name": "banana"}])

print(tracker)
# {name: banana, color: red}

update() vs Other Approaches

MethodReturnsModifies OriginalNotes
.update()NoneYesIn-place mutation
{**d1, **d2}New dictNoCreates a new dictionary
d1 | d2 (3.9+)New dictNoMerge operator
d1 |= d2 (3.9+)dictYesUpdate-and-assign operator

See Also

  • dict() — the dict constructor for creating new dictionaries
  • dict.copy() — creates a shallow copy of the dictionary
  • dict.pop() — removes and returns a value by key