✦ Python Foundations Collections module

Concept 11 · Dictionaries

Name each value.
Use a key to find it.

Dictionaries organize related data by meaningful keys instead of numeric positions.

01 Learn02 Try03 Predict

A dictionary stores unique keys and their values.

Dictionaries organize related data by meaningful keys instead of numeric positions.

student = {"name": "Ana", "age": 22}
print(student["name"])

Square brackets use a key to access its associated value.

Try changing one value, then explain which part of the collection changed and why.

↳

Keep this in mind: Read the collection operation before predicting the result.

Try it
student = {"name": "Ana", "age": 22, "course": "Python"}

print(student["name"])
student["age"] = 23
student["city"] = "Novi Sad"
print(student["age"])
print(student.get("city"))

Run the example, then change one value and observe the result.

Python Playground

Loading Python runtime…

Edit the example and run it in your browser.

dictionaries.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Read each operation before choosing an answer.

product = {"name": "Keyboard", "price": 2500}

product["price"] = 2200
product["stock"] = 5

print(product["price"])
print(len(product))
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Ask Sloby about this concept

Describe what feels unclear and Sloby will guide your reasoning.

Hi! I'm Sloby. Let's explore this Python concept together.

What will this program print, and why? Explain updating, adding a key, and membership.

user = {"name": "Ana", "points": 10}

user["points"] += 5
user["level"] = "beginner"

print(user["points"])
print("level" in user)
print(len(user))
Python AI Tutor · Learn by understanding, not just by running code.