Talk to the Computer
beginner20 XP

Variables: Labeled Boxes

Store facts about planets and mountains in named boxes.

Variables: Labeled Boxes 📦

Scientists keep track of a LOT of facts: names of planets, heights of mountains, how many moons a planet has. In Python we keep facts in variables. A variable is a box with a name label on it.

Python
planet = "Mars"
moons = 2
print(planet)
print(moons)

The = sign means "put this into the box". It's not "equals" like in math class!

  • planet is the label on the box, and "Mars" is what's inside.
  • Mars really has 2 tiny moons, called Phobos and Deimos. 🌑🌑

Using boxes together

You can print several things at once with commas:

Python
planet = "Mars"
moons = 2
print(planet, "has", moons, "moons")

That shows: Mars has 2 moons

Changing what's inside 🔄

A box holds one thing. Put in something new and the old thing is gone:

Python
trees_planted = 10
trees_planted = 25
print(trees_planted)

That prints 25.

Good box names ✅

  • Use lowercase letters and _ instead of spaces: tallest_mountain
  • No spaces, and don't start with a number.
  • Pick names that explain what's inside: rainfall is better than x.

🏔️ Fun fact

Mount Everest, between Nepal and China (Tibet), is about 8,849 meters tall. That's like stacking about 26 Eiffel Towers!

⌨️

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/6
What does moons = 2 do?