Variables Explained: Labeled Boxes That Hold Values

← Back to Blog & Articles

A variable lets a program remember something. It is one of the first big ideas in Python, and a simple picture makes it easy to grasp.

Think of a labeled box

Imagine a box with a name written on it. You can put something inside and look at it later. In Python, score = 10 puts the number 10 into a box labeled score.

Using what is inside

Once the value is stored, you can use the name instead of repeating the value:

name = "Pip"
score = 10
print(name, "has", score, "points")

Changing the contents

A variable can be updated at any time. score = score + 5 takes what is in the box, adds 5, and puts the new total back. Now score is 15.

Different kinds of values

A variable can hold numbers, words in quotation marks, or true and false values. Python remembers what kind of thing it is, and this matters, because you can add numbers but you cannot add a number to a word without converting it first.

Choosing good names

Names should say what the box holds. player_score is clearer than x. Use lowercase letters and underscores instead of spaces.

A quick activity

Ask the learner to predict what a short program will print before running it. Then run it and compare. Surprises are useful, because they show exactly what to learn next.

Takeaway

A variable is a named place to keep information so the program can use it again.

Continue with the book

Explore the full treatment, worked examples, and exercises in Code Quest with Python.


Adapted from Code Quest with Python, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top