Teach Your Code to Remember Things!
Explore how to teach Python to remember information using variables. Learn to create, store, and reuse data such as text, numbers, and boolean values. Practice writing code that uses variables in expressions to perform calculations and keep your code organized and understandable.
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.