An optional field

Take your time, follow the code and check your understanding.

The codeDictionaries
user = {"name": "Asha"}
print(user["city"]) # city is optional
Your answer3 min · no timer
What needs fixing?

Show solution and explanation

Indexing requires the key to exist. user.get("city", "Unknown") handles a missing optional field.

The code raises KeyError; use get with a fallback.