You can update an existing value in a Python dictionary by assigning a new value to an existing key:
scores = {"Alice": 95, "Bob": 87}
scores["Alice"] = 99 # update existing key
scores["Charlie"] = 72 # add new key
If the key exists, the value is overwritten. If it doesn't exist, a new entry is added.
d = {"x": 1}
d["x"] = 100 # x is now 100
d["y"] = 200 # new key "y" added
print(d) # {"x": 100, "y": 200}
Assignment
Follow the Coding Tutorial and update Alice's score to 99!
Hint
Use scores["Alice"] = 99.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
