All lessons
📦

Python Variables

Store and reuse values with names

Reward
+50 XP

What is a variable?

A variable is a name that points to a value in memory. You assign with the = sign. Python figures out the type automatically.

name = "Ada"
age = 36
is_engineer = True

print(name, age, is_engineer)

Naming rules

Names can use letters, digits, and underscores, but cannot start with a digit. They are case-sensitive: score and Score are different.

Reassigning

You can reassign a variable to a new value of any type at any time.

count = 1
count = count + 1
print(count)  # 2

Multiple assignment

Python lets you assign multiple variables in one line.

a, b, c = 1, 2, 3
print(a, b, c)

Try it yourself

Run the example below. Edit it and see what changes.

main.py
Output
Press Run to execute (Ctrl/Cmd+Enter)

Common mistakes

  • Using = (assignment) when you meant == (comparison).
  • Using a variable before assigning it.
  • Starting a variable name with a number, e.g. 1score = 5.
  • Using Python keywords like 'if' or 'for' as variable names.