Objects / Dictionaries
📚 What are Dictionaries? A dictionary stores data as key-value pairs. Instead of remembering that index 3 holds the age, you use a descriptive key like 'age'. Python dictionaries are written with curly braces: player = {'name': 'Alex', 'score': 100}. You look up values by key: player['name'] gives…

Appy Says…
A list is great for ordered items. But what if you want to look something up by name, not by position? That's a dictionary — the data structure behind every user profile, every settings page, and every JSON response from the internet.
What is a Dictionary?
A dictionary stores data as key-value pairs. Instead of looking up by index (0, 1, 2…), you look up by a meaningful key (like "name" or "score"). Each key maps to a value.
- •Create:
player = {"name": "Alex", "score": 1200, "level": 5} - •Access:
player["name"]gives"Alex" - •Add/change:
player["lives"] = 3— adds a new key or updates existing - •Delete:
del player["lives"]orplayer.pop("lives") - •Check key:
"score" in playergivesTrue
Think of it like a gamer profile
Your Roblox profile has a username, an avatar, a rank, a friend count, a list of owned items. Each piece of data has a label (key) and a value. That's a dictionary. You don't look up your username by position — you look it up by the key "username".
Key Dictionary Operations
- •
dict.keys()— returns all keys - •
dict.values()— returns all values - •
dict.items()— returns key-value pairs (great for looping) - •
dict.get(key, default)— safe lookup: returns default if key missing (avoids crash) - •
dict.update({"key": value})— adds or updates multiple keys at once - •Loop:
for k, v in player.items(): print(k, v)
Real-World Examples
- •User profile:
{"username": "pixel", "email": "p@test.com", "premium": True} - •App settings:
{"dark_mode": True, "notifications": False, "language": "en"} - •HTTP response headers from a website: a dictionary of key-value pairs
- •JSON data from any API (TikTok, Spotify, etc.) is essentially a dictionary
- •A game inventory:
{"sword": 1, "potion": 5, "shield": 1}
Key Facts
- •Keys must be unique — you can't have two entries with the same key
- •Keys are usually strings, but can be numbers or tuples
- •Values can be anything — even another dictionary or a list
- •In Python 3.7+, dictionaries remember insertion order
- •Dictionaries and JSON (used on the internet) share the same structure — learning one helps with the other
Watch Out: KeyError
If you access a key that doesn't exist — player["xp"] when "xp" isn't in the dict — you get a KeyError. Use dict.get("xp", 0) instead to return a safe default value when the key is missing.
Remember
When you see data structured as {"key": value, "key": value} anywhere — in Python, in JSON, in an API response — that's a dictionary. They're everywhere on the internet. Learning dicts now will feel like a superpower when you start working with real APIs.
What You Learned
- •Dictionaries store data as key-value pairs
- •Access values with
dict["key"]or safely withdict.get("key", default) - •Add/update:
dict["key"] = value; delete:del dict["key"] - •Loop through with
for k, v in dict.items(): - •Keys are unique; values can be anything including lists or other dicts
- •JSON (internet data format) is basically a dictionary — you're already ready for APIs
Key Facts
- →Keys must be unique — you can't have two entries with the same key
- →Keys are usually strings, but can be numbers or tuples
- →Values can be anything — even another dictionary or a list
- →In Python 3.7+, dictionaries remember insertion order
- →Dictionaries and JSON (used on the internet) share the same structure — learning one helps with the other
Real-World Examples
Remember
When you see data structured as {"key": value, "key": value} anywhere — in Python, in JSON, in an API response — that's a dictionary. They're everywhere on the internet. Learning dicts now will feel like a superpower when you start working with real APIs.
Quick Quiz
How do you get a value from a dictionary?