Storing stuff in named boxes
Learn how to store information in variables โ named boxes that hold your data until you need it.
A variable is like a labeled box where you store something. You put a value inside, give the box a name, and later you can look inside the box to see what is there. Variables let your program remember things!
๐ก Think of it like this:
Imagine you have a bunch of shoe boxes. You write "sneakers" on one, "sandals" on another. Later, when you want your sneakers, you just look for the box labeled "sneakers". Variables work the same way!
Without variables, your program would forget everything. Variables let you store a player's name, a game score, a password โ anything you need to remember.
Where you see this in real life:
In Python, you can name a variable almost anything โ even "pizza" or "dinosaur" โ as long as it has no spaces!
A variable is a labeled box that stores information. You give the box a name, put something inside, and later you can look inside to see what is there.
To create a variable, you write the name, an equals sign, and the value. Like this: name = "Alex"
The variable 'name' stores the text 'Alex'. print() shows it!๐ก Try changing "Alex" to your own name!
Variables are called "variable" because they can CHANGE! You can update the value whenever you want.
Click โถ Run to see the output!Rules for naming variables:
โ Good names
player_name
age
favorite_color
score_2
โ Bad names
player name
2nd_score
favorite-color
class
Which of these is a valid variable name in Python?