▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
Variables
Give values names so you can store and reuse them.
🎬 Video version coming soon — read it now
A variable is a name that holds a value, like a labelled box. You put something in once and use the name everywhere after.
Creating a variable
The = sign means "store this value in this name". It is not "equals" like in maths.
Variables can change
score = score + 5 reads as: take the current score, add 5, and store the result back in score. The short way to write it is score += 5.
Rules for names
- Letters, numbers and underscores only:
total_marks,student2 - Can't start with a number:
2nd_placeis not allowed - No spaces: use
first_name, notfirst name - Case-sensitive:
Ageandageare different variables
Good names make good code
Both work, but six months later only the second one makes sense. Python programmers use snake_case: lowercase words joined with underscores.
In one line
A variable stores a value under a name; = means "store", and good names make code easy to read.
Share with a friend