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.
We'll cover the following...
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.
Yep! Python remembered what we told it.
What just happened?
We executed the following:
Created a variable with
=, likename = "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, likefavorite_food.
Your turn: Store something
Try to create our own variable and print it out.
Variables can store:
Text ("strings") like
"blue"Numbers like
18True/False values (called booleans)
Play around with names and values. Then click “Run” and see what we get.
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.
Now that’s smart! Python did the math using our variables.