Python Variables: Store and Use Data

Learn how to store and use data with variables.

So far, Python has said hello and done math. But now it’s time to give it a memory.

We’re going to learn how to make Python remember things using variables.

Teach Python to remember

Think of a variable like a label for a box. We can store something inside, and later, we can ask Python to use it again.

Python
name = "Ava"
print(name)

Yep! Python remembered what we told it.

What just happened?

We executed the following:

  • Created a variable with =, like name = "Ava".

  • Used print() to show what’s inside.

This lets us reuse values, change them, and keep our code tidy.

Important: Variable names can’t have spaces. Use _ instead, like favorite_food.


Your turn: Store something

Try to create our own variable and print it out.

Variables can store:

  • Text ("strings") like "blue"

  • Numbers like 18

  • True/False values (called booleans)

Play around with names and values. Then click “Run” and see what we get.

Python
favorite_color = "blue"
age = 18
loves_python = True
print(favorite_color)
print(age)
print(loves_python)

Mix it up

We can use variables in expressions, too. You can think of an expression like a math sentence or instruction—it can include numbers, text, variables, and even symbols like + or -. Python figures them out step by step, just like solving a small puzzle.

Python
birth_year = 2000
current_year = 2025
age = current_year - birth_year
print(age)

Now that’s smart! Python did the math using our variables.