Search⌘ K
AI Features

Python Variables: Store and Use Data

Explore how to create and manage variables in Python, enabling you to store and reuse data such as text, numbers, and boolean values. Learn variable naming rules, how to print stored data, and how to use variables within expressions to perform calculations.

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.