Kids Coding

Dictionaries

A dictionary maps a key to a value. Store a score, a name, or a fact.

KidsIntermediateDictionaries

A label for each value

A list is ordered. A dictionary maps a key to a value. You look things up by name, not by position.

A player

player = {
    "name": "Sam",
    "score": 12,
}
print(player["name"])
print(player["score"])

A list finds things by position (scores[0]); a dictionary finds them by name (scores["Sam"]). Pick the one that matches how you picture the data.

Change a value

Add points

player = {"name": "Sam", "score": 12}
player["score"] = player["score"] + 5
print(player["name"], "has", player["score"])

Keys you have

in

player = {"name": "Sam", "score": 12}
if "score" in player:
    print("Score is recorded")

Real life

A contact in a phone: name, and a number.

You look up “Mum”, not “item 2”. A dict looks up by the label.

Phone contact

mum = {"name": "Mum", "number": "555-0142"}
print("Call", mum["name"])
print(mum["number"])
mum["number"] = "555-0199"
print("New number:", mum["number"])

Change one word. Run it. That is how this idea shows up outside the lesson.

Try it

Exercise 1: Make a dict with title and pages. Print the title.

Show solution
book = {"title": "Foxes", "pages": 80}
print(book["title"])

FAQ: Dictionaries

Common questions about this page.

What is StudyGrid Kids?

StudyGrid Kids is a free coding path for children: Basic, Intermediate, and Advanced. Lessons use Python in the browser. No account and no install.

Should I run dictionaries examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn dictionaries in this Kids Coding Python lesson (Dictionaries).

Which kids level should we start with?

Start at Basic if the child has never written code. Choose Intermediate if they can print, use variables, and write a simple if. Choose Advanced if they already use loops and lists.

Do kids need an account or an app?

No. Kids pages are public. Code runs in the Try Python editor at /try. We do not ask children for a name or an email.

What language do kids learn?

Python, with a first HTML page in Intermediate and Advanced. After Advanced, the main Python tutorial is the next step.

Is the kids coding track free?

Yes. The Kids home, the three levels, and the Python editor on StudyGrid (studygrid.in) are free.