LESSON 3

Variables

Learning objective: Store data in variables in Python.

Understand

Variables hold values you can reuse.

In Python you create a variable simply by assigning to it — no keyword needed. Names should be lowercase with underscores. You can reassign a variable at any time.

Analogy: A variable is a labelled box you can fill and refill.

See It in Action

Assigning and using variables:

name = "Sam"
age = 20
print(name, age)
How it works: name and age are created by assignment, then printed together.

Try It Yourself

  1. Create a variable for your favourite number.
  2. Print it.
  3. Reassign it and print again.

Quick Quiz

How do you create a variable in Python?

Challenge

Store three facts about yourself in variables and print them.

Success condition: Your program prints values from three variables.