Python Variables
A variable is a labeled drawer.
You put something inside. Later you open it by name.
The label stays. The thing inside can change.
In Python you make a variable with a name, an equals sign, and a value.
Creating a variable
Write the name on the left.
Write the value on the right.
The = means put this value in that drawer.
Updating a value
You can replace what is in the drawer.
Use the same name again with a new value.
Or use the old value to make a new one.
Naming rules
Names can use letters, numbers, and underscores.
A name cannot start with a number.
Spaces are not allowed in a name.
Good: score, user_name, total2
Bad: 2total, user name, user-name
Use snake_case: words_with_underscores
Pick names that tell the truth
Many names at once
You can fill a few drawers on one line.
Only do this when it stays easy to read.
Same name, new kind of thing
Python lets you put a number in a drawer today.
Tomorrow you can put text in the same drawer.
That works, but keep your story clear.
Reading a variable
When you write the name, Python looks in that drawer.
print shows what it found.
Tip: Clear names beat short secret codes. Your future self will thank you.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.