📦 What is a variable?
A variable is a labeled box where you can store a piece of information and use it later. You create one with an = sign:
score = 100
name = "Maya"
Read this as: "Put 100 into a box labeled score." Now whenever you write score, Python remembers it means 100.
score = 100
print(score) # shows 100
print(name) # shows Maya
📌 Notice the difference
print("score") prints the word score . print(score) (no quotes) prints what's inside the box — 100.
🔁 Variables can change
The value in a box can be replaced any time. Python always remembers the most recent value.
lives = 3
print(lives) # 3
lives = lives - 1
print(lives) # 2
🧩 The main data types
Every value in Python has a type . The three you'll use most are:
1. String (text) — str
Words and letters, always inside quotes.
pet = "dog"
greeting = "Good morning!"
2. Integer (whole number) — int
Counting numbers, no quotes, no decimal point.
age = 11
coins = -5
3. Float (decimal number) — float
Numbers with a decimal point.
price = 2.50
temperature = 98.6
Bonus: Boolean (true/false) — bool
Only two values: True or False (capital first letter!).
game_over = False
is_winner = True
🔍 Checking a type
Ask Python what type something is with type():
print(type("hello")) # <class 'str'>
print(type(42)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type(True)) # <class 'bool'>
🏷️ Naming rules
Good variable names
Use letters, numbers, and underscores: high_score, player2
Must start with a letter or underscore, not a number : 2cool ❌
No spaces — use underscores instead: my name ❌ → my_name ✅
Choose names that describe the value: x 😐 vs player_health 😍
✅ What you learned
A variable stores a value with name = value.
The big data types: str, int, float, bool.
Use type() to check a value's type.
Variables can be changed at any time.
🎮 Time to Practice!
Build, change, and inspect your own variables. Run early, run often!
🐶
Task 1: Create a Pet
Easy
Make a variable pet_name set to "Buddy" and a variable pet_age set to 7. Then print each one (the values, not the words). Output should be:
Buddy
7
▶ Run
✓ Check
↺ Reset
💡 Solution
pet_name = "Buddy"
pet_age = 7
print(pet_name)
print(pet_age)
🍪
Task 2: Cookie Countdown
Medium
Start with cookies = 3 and print it. Then eat one cookie at a time (cookies = cookies - 1), printing after each bite, until you reach 1. Output:
3
2
1
▶ Run
✓ Check
↺ Reset
💡 Solution
cookies = 3
print(cookies)
cookies = cookies - 1
print(cookies)
cookies = cookies - 1
print(cookies)
🔬
Task 3: Type Detective
Medium
Use type() to print the type of: the text "cat", the number 10, the decimal 3.5, and the value True — in that order.
▶ Run
✓ Check
↺ Reset
💡 Solution
print(type("cat"))
print(type(10))
print(type(3.5))
print(type(True))
🦸
Task 4: Free Play — Build a Character
Creative
Invent a game character! Make variables for hero_name (string), level (int), health (float), and has_sword (bool). Print them all. Then make your hero level up by changing level.