Modifying dictionary values #
You can also modify the value of a key by re-assigning it:
my_dict = {
"name": "John",
"age": 25,
"city": "New York",
}
my_dict["age"] = 26
print(my_dict["age"]) # 26
As you can see, the my_dict["age"] was 25 before we reassigned it to 26.
Exercise #
We have created a dictionary job_position. Change the value of the key "experience_required" to the value other than 5.
Tests #
job_position["experience_required"]should be any value other than5- Update the value using square brackets
[]
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules