- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
How to replace values of a Python dictionary?
You can assign a dictionary value to a variable in Python using the access operator []. For example,
Example
my_dict = { 'foo': 42, 'bar': 12.5 } new_var = my_dict['foo'] print(new_var)
Output
This will give the output −
42
This syntax can also be used to reassign the value associated with this key. For example,
Example
my_dict = { 'foo': 42, 'bar': 12.5 } my_dict['foo'] = "Hello" print(my_dict['foo'])
Output
This will give the output −
Hello
Advertisements