computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

📦

🎓

⏱ 20 min

Free

Magic Boxes (Variables)

Variables are labeled boxes that remember things. Store names, scores and more!

🎯 What you will learn

  • Create a variable with =
  • Use variables in print()
  • Change what is inside a variable

👋 Let’s get started!

Imagine a box with a label like “pet” 📦. You put “dog” inside. Later you can open the box to see what’s there. In code, that box is a VARIABLE!

🪜 Step by step

1. 📦 Make a box

Use = to put something into a variable. The name goes on the left.

pet = "dog"
print(pet)
2. 🔤 Good names

Use names that explain what’s inside: score, player_name. No spaces — use _ instead.

player_name = "Ava"
score = 0
3. 🔄 Change it

You can put something new in the box any time.

score = 0
score = score + 10
print(score)

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

My favorite things

food = "pizza 🍕"
animal = "panda 🐼"
print("I love " + food)
print("My favorite animal is a " + animal)

Score points!

score = 0
score = score + 5
score = score + 5
print(score)

📖 Key words

Tap a card to flip it over!

Variable
A labeled box that stores something 📦
=
Puts a value into a variable ⬅️
Value
What’s inside the box 🎁

🏆 Challenge

Make a variable called hero with the value “Captain Code” and print: My hero is Captain Code

Challenge

hero = ""
print("My hero is " + hero)

Knowledge Check Quiz

  1. What does this print?
  2. What does this print?
  3. Which is a good variable name?
← Previous lesson
Next lesson →