Syllabus Lesson 2 of 239 · Python Foundations
Python Foundations

Variables

A variable is a name that points at a value. You create one with =, reading it as "set this name to this value":

city = "Lagos"
year = 2026

You can reassign a variable later. The newest value wins, and the old one is forgotten:

score = 10
score = 25
print(score)   # 25

A common move is to build a new value out of the current one. Reading the right side first, then storing the result back into the same name:

score = 10
score = score + 5
print(score)   # 15

Naming rules

  • Use lowercase words joined by underscores: first_name, total_cost.
  • Start with a letter or underscore, never a digit.
  • Pick clear names. days_left beats d every time.
Your turn

Set score = 10. Then reassign score to itself plus 5 so it becomes 15. Finally print the value of score.

Spotted a problem in this lesson? Report it

Code · runs in your browser
Output