Variables
๐ What are Variables? A variable is a named container that holds a value in your program. Think of it like a labelled box: you write a name on the outside, put something inside, and come back later to find it by name. In Python you create one with a simple assignment: name = value.

Appy Saysโฆ
Every game tracks your score, your health, your username. Every app remembers your name, your settings, your playlist. All of that lives in variables. Master this and you understand how every app stores data.
What is a Variable?
A variable is a named storage box in your computer's memory. You give it a name, put a value inside, and use that name anywhere in your code to get the value back โ or change it.
- โขYou create one with
name = valueโ the = sign means 'store this' - โขYou can store text, numbers, True/False, listsโฆ anything
- โขThe value can change later โ that's why it's called a variable
- โขVariable names should describe what they hold:
scorenotx123
Think of it like a Minecraft chest
Each chest has a label on it. You open the chest labelled diamonds to see how many you have. You can take some out (decrease), add more (increase), or swap the contents entirely. Variables work the same way โ label, store, retrieve, change.
Quick Cheat Sheet
How Variables Work
- โขAssign:
score = 0โ creates the box and puts 0 inside - โขRead:
print(score)โ opens the box and shows what's inside - โขUpdate:
score = score + 10โ take the old value, add 10, put the new value back - โขRename: just use a new assignment โ
score = 100replaces whatever was there
Real-World Examples
- โขA game stores
lives = 3โ every time you die,lives = lives - 1 - โขSpotify stores your
volume = 75โ moving the slider changes the variable - โขTikTok stores
likes_count = 1423โ every heart press doeslikes_count += 1 - โขA shopping app stores
cart_total = 0and adds to it with each item
Key Facts
- โขVariable names cannot start with a number:
1scoreis invalid,score1is fine - โขUse underscores for multi-word names:
high_score(snake_case is the Python style) - โขPython figures out the type automatically โ no need to say 'this is a number'
- โข
+=is a shortcut:score += 10meansscore = score + 10
Remember
The = sign in Python does not mean 'equals' like in maths. It means assign โ 'store this value in this variable'. To check if two things are equal, use == (double equals).
What You Learned
- โขA variable is a named box that stores a value in memory
- โขCreate with
name = value, read withprint(name) - โขUpdate the value by assigning again:
score = score + 10 - โขGood names make code readable โ use
player_health, notph - โข
=means assign,==means check if equal
Key Facts
- โVariable names cannot start with a number:
1scoreis invalid,score1is fine - โUse underscores for multi-word names:
high_score(snake_case is the Python style) - โPython figures out the type automatically โ no need to say 'this is a number'
- โ
+=is a shortcut:score += 10meansscore = score + 10
Real-World Examples
Remember
The = sign in Python does not mean 'equals' like in maths. It means assign โ 'store this value in this variable'. To check if two things are equal, use == (double equals).
Quick Quiz
What is a variable?