Introduction

In the last episodes, we explored Python's basic data types — like numbers, strings, and booleans.

Today, we’re going to unlock a new tool: variables — and learn how they help us reuse, organize, and work more efficiently with data in our code.

Variables

So far, we have learned how to create objects in Python and print them right away. But in most real programs, we want to store those objects and reuse them. That’s where variables come in.

In Python, a variable lets you assign a name to an object — a way to refer to that value later in your code.

A lot of people explain variables using the “box” analogy: a box that holds a value, and the variable is the label on the box. But honestly, I think that can be a bit misleading in Python.

Why? Because in Python, variables are more like names of references to objects — not boxes that contain them. You can actually give multiple names to the same object, and all of those names will still point to the same thing. We will explore this in more detail when we introduce mutable objects.

So, overall, it’s kind of like calling your couch a “sofa” or a “loveseat”. Different words, same furniture. The object doesn’t change — just the label you’re using to refer to it.

Variables Intro.jpg

Let’s see how this works in practice.

A variable is just a name that points to an object in memory. You’re not storing the object inside the variable — you’re just labelling it. Let’s break this down with some real code examples.

greeting = "Hello"

You can give multiple names to the same object:

a = 42
b = a

Now both a and b point to the same value. You didn’t copy the value — you just gave it another name. It’s like calling your friend ‘Alex’ at school and ‘Lex’ at home. Still the same person.

Now, let’s look at reassignment example:

x = 10
y = x
x = 20
print(y)

Notice how y keeps the original value. That’s because when we changed x, we pointed it to a new number. We didn’t change the number 10 — we just re-used the name x to point it to another object.