
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
What is usage of update method in Python dictionary?
The update() method of Python’s dictionary class serves two purposes.
It adds a new key-value pair if dictionary doesn’t already contain the key.
>>> d1={'name': 'Ravi', 'age': 25, 'marks': 60}
The update() method a dictionary object as argument
d1.update({"course":"ComputerEngg"})
The updated dictionary shows that a new key-value pair is added
>>> d1 {'name': 'Ravi', 'age': 25, 'marks': 60, 'course': 'Computer Engg'}
However, if the key as already present, its value is updated by the method
>>>d1.update({"age":21}) >>> d1 {'name': 'Ravi', 'age': 21, 'marks': 60, 'course': 'Computer Engg'}
- Related Articles
- Dictionary Methods in Python (update(), has_key(), fromkeys()
- How to optimize Python dictionary memory usage?
- What is the usage of every() method in JavaScript?
- What is the usage of fill() method in JavaScript?
- What is the usage of copyWithin() method in JavaScript?
- What is the usage of some() method in JavaScript?
- What is the usage of join() method in JavaScript?
- What is the usage of Array.Every() method in JavaScript?
- How to update a Python dictionary values?
- Can you please explain Python dictionary memory usage?
- How to update the value of a key in a dictionary in Python?
- What is the purpose and usage of “FOR UPDATE OF” clause in a COBOL-DB2 program
- How does Python dictionary keys() Method work?
- What is possible key/value delimiter in Python dictionary?
- C++ Program to Update value of Dictionary using key

Advertisements