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.
planet = "Mars"
moons = 2
print(planet)
print(moons)The = sign means "put this into the box". It's not "equals" like in math class!
planetis 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:
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:
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:
rainfallis better thanx.
🏔️ 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.
Press ▶ Run to see your code come to life…