...

/

Teach Your Code to Remember Things!

Teach Your Code to Remember Things!

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.

Let’s 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.

Press + to interact
Press + to interact
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. Here are a few ideas:

Press + to interact
favorite_color = "blue"
age = 18
loves_python = True
print(favorite_color)
print(age)
print(loves_python)

Variables can store:

Press + to interact
  • 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.


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.

Press + to interact
birth_year = 2000
current_year = 2025
age = current_year - birth_year
print(age)

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


Mini challenge: About you

Make Python remember a few things about you, and then print a sentence using them.

We can use commas in print() to display multiple items like text and numbers, and Python will automatically add spaces between them. This is helpful when printing variables without needing to join everything into one string.

Press + to interact
name = "Ava"
age = 25
print("Hi, my name is", name, "and I’m", age, "years old.")

Try changing the values and re-running it. Make it your own!


Quick recap

We just learned:

  • How to create and use variables in Python.

  • How to store text, numbers, and booleans.

  • How to use variables in print statements and calculations.


What’s next?

Next, we’ll learn how to mix words and numbers and make our output even more powerful and polished with formatting!