- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Updating Dictionary in Python
You can update a dictionary by adding a new entry or a key-value pair, modifying an existing entry, or deleting an existing entry as shown below in the simple example −
Example
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} dict['Age'] = 8; # update existing entry dict['School'] = "DPS School"; # Add new entry print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['School']
Output
When the above code is executed, it produces the following result −
dict['Age']: 8 dict['School']: DPS School
- Related Articles
- Updating Strings in Python
- Updating Lists in Python
- Updating Tuples in Python
- Convert string dictionary to dictionary in Python
- Dictionary Methods in Python
- Python - Convert flattened dictionary into nested dictionary
- Python Convert nested dictionary into flattened dictionary?
- Python - Dictionary has_key()
- Python Dictionary Comprehension
- Append Dictionary Keys and Values (In order ) in dictionary using Python
- Dictionary Methods in Python Program
- Dictionary Data Type in Python
- Delete Dictionary Elements in Python
- How to convert Javascript dictionary to Python dictionary?
- How to define a Python dictionary within dictionary?

Advertisements