Yellow Hat – Strings & Dictionaries
beginner20 XP
Dictionaries
Organise data with key-value pairs using Python dictionaries
Dictionaries
A dictionary stores information as key-value pairs.
Python
player = {"name": "Alex", "score": 100, "level": 5}
print(player["name"]) # Alex
player["score"] = 150 # update
player["health"] = 80 # add new keyLooping
Python
for item, qty in inventory.items():
print(f"You have {qty} {item}(s)")⌨️
Type it yourself
Don't just read it — type the example from above into the box, press Run ▶, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.
Python · Playground
Output
Press ▶ Run to see your code come to life…Quick check
01/2
How do you access a value from a dictionary called 'player'?