Python Variables and Types — Explain Like I'm 5
Labeled Boxes for Your Computer
Think of your computer’s memory as a giant room full of storage boxes. When you write a program, you need somewhere to keep track of things — someone’s name, a score in a game, how much money is in an account.
Variables are the labels you stick on those boxes so you can find them again.
score = 42
player_name = "Alex"
You just labeled one box “score” (which holds the number 42) and another “player_name” (which holds the text “Alex”). Any time later in your program, you can use those labels to get the value back.
Why “Variable”?
Because the value can vary — it can change. Watch:
score = 42
score = score + 10
After line 2, the box labeled “score” now holds 52. You changed what’s inside.
Python Knows What Kind of Thing You Stored
Here’s something cool about Python: it figures out what type of thing you stored automatically.
- Numbers like
42→ Python calls these integers (whole numbers) - Numbers like
3.14→ Python calls these floats (numbers with decimal points) - Text like
"Alex"→ Python calls these strings - True or False → Python calls these booleans
You don’t have to tell Python “this is a number” or “this is text.” It looks at what you wrote and figures it out. That’s unusual — most programming languages make you declare the type upfront.
Why Types Matter
You can do math with numbers. You can’t do math with names.
score = 42
bonus = 10
total = score + bonus # Works! 52
name = "Alex"
greeting = "Hello, " + name # Also works! "Hello, Alex"
wrong = score + name # ERROR — can't add a number and text
Python won’t let you accidentally mix things that don’t make sense together. That’s the type system protecting you.
One Thing to Remember
Variables are labels for boxes that hold information. Python automatically figures out what kind of information is inside — number, text, or true/false — and won’t let you mix types in ways that don’t make sense.
See Also
- Python Async Await Async/await helps one Python program juggle many waiting jobs at once, like a chef who keeps multiple pots moving without standing still.
- Python Basics Python is the programming language that reads like plain English — here's why millions of beginners (and experts) choose it first.
- Python Booleans Make Booleans click with one clear analogy you can reuse whenever Python feels confusing.
- Python Break Continue Make Break Continue click with one clear analogy you can reuse whenever Python feels confusing.
- Python Closures See how Python functions can remember private information, even after the outer function has already finished.