Content · Programming · Python

Python dict.update Method: Usage and Examples

dict.update(other, **kwargs) copies key-value entries into an existing dictionary and returns None. Existing keys are overwritten; new keys are inserted. See two practical examples, edge cases and common mistakes.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

A configuration receives a batch of user preferences.

What You Need to Understand


dict.update(other, **kwargs) copies key-value entries into an existing dictionary and returns None. Existing keys are overwritten; new keys are inserted.

When to Use It


A configuration receives a batch of user preferences.

Step-by-Step Python Example


settings = {"theme": "light", "size": 10}
result = settings.update({"theme": "dark", "autosave": True})
print(settings)
print(result)

How the Example Works


The theme is replaced, autosave is inserted and the method returns None.

Example Output


{'theme': 'dark', 'size': 10, 'autosave': True}
None
{'pen': 2, 'paper': 3}

A Second Example


Compare this smaller variation with the main example, then experiment with your own values.

prices = {"pen": 2}
prices.update([("paper", 3)])
print(prices)

Important Behavior and Edge Cases


update() is not a nested merge: an inner dictionary value can be replaced wholesale. Use | when you need a new dictionary instead.

Try It Yourself


Update prices from a list of (product, price) pairs.

Common Beginner Mistakes


  • update() is not a nested merge: an inner dictionary value can be replaced wholesale. Use | when you need a new dictionary instead.
  • Using the wrong collection method for this operation without checking whether it mutates the object, returns a result, or raises on missing data.

Key Takeaways


  • dict.update(other, **kwargs) copies key-value entries into an existing dictionary and returns None.
  • The theme is replaced, autosave is inserted and the method returns None.
  • update() is not a nested merge: an inner dictionary value can be replaced wholesale.
Share this resourceSend this page to someone who may find it useful.