Contact
Evil Genius SocietyHomeLearnForumLeaderboardSocialsMessages
← Back to module

Lesson 3 of 10

A variable is a name that refers to a value stored in memory. Instead of retyping a value every time you need it, you give it a name once and reuse that name.

name = "Ada"
age = 28
print(name)
print(age)

The = sign is the assignment operator. It doesn't mean "equals" like in math — it means "store the value on the right into the name on the left."

Naming rules

Variable names in Python:

  • Can contain letters, numbers, and underscores (_)
  • Cannot start with a number
  • Are case-sensitive — age and Age are different variables
  • Cannot be a reserved keyword (print, if, for, etc.)

By convention, Python variable names use snake_case — lowercase words separated by underscores, like first_name or total_score.

first_name = "Grace"
total_score = 100
is_active = True

Reassignment

Variables can change — that's the whole point. Assigning a new value replaces the old one:

score = 10
print(score)
score = 20
print(score)

You can even use a variable's current value to compute its new one:

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

Try it yourself

Create a variable called city with your favorite city, and a variable called visits set to the number of times you'd like to visit. Print both.

Checkpoint

  • = assigns a value to a variable name.
  • Variable names use snake_case by convention.
  • Reassigning a variable overwrites its old value.

Questions about this lesson

Log in to ask a question.