Nex2School

Parent guide · 7 min read

Python variables for kids: naming, storing and changing values

A variable is the first idea in programming that is genuinely new — not a faster version of something from maths class, but a different kind of thing altogether. It is a named container that holds a value, and both the name and the value can be chosen freely. This sounds simple, and in one sense it is: a child can write their first variable in a few seconds. But the mental model that makes variables feel natural, rather than just magical, takes a little longer to build, and getting it right early prevents a cluster of stubborn mistakes later.

Python variables for kids: naming, storing and changing values

Try this tonight

4 things you can do at home

  1. Open the Python shell and create a variable

    Open a terminal and type python3 (or python on Windows) to get the interactive shell — the prompt looks like >>>. Type score = 0 and press Enter. Nothing appears to happen, which is correct: the name score now holds the value 0. To see it, type score and press Enter. Python prints 0. This confirms the variable exists and holds the value you gave it.

  2. Change the value and check it again

    Type score = 10 and press Enter, then score and Enter again. Python now prints 10. The old value is gone — the name score now points to 10. This is what "variable" means: the value varies. Try score = score + 5, then check score again. Python first reads the right side (score + 5, which is 15), then makes the left side (score) point to that result.

  3. Choose names that say what the value means

    Python allows almost any name, but descriptive names make programs readable. player_name, lives_remaining, and high_score are better than x, n, and hs — not because Python cares, but because a child reading their own code a week later will understand it immediately. The rule for valid names: start with a letter or underscore, use only letters, numbers, and underscores, no spaces. Python names are case-sensitive: Score and score are two different variables.

  4. Read the data type to understand why things go wrong

    Type type(score) in the shell. Python prints <class 'int'> — an integer. Now try name = "Alex" and type(name) — Python prints <class 'str'> — a string. If your child ever sees a TypeError, it almost always means Python was given a string where it expected a number, or the other way around. Reading the type at that moment, rather than guessing, fixes the error faster than any other approach.

  1. What a variable actually is

    Think of a variable as a sticky label attached to a value. The label has a name (score), and it is stuck on some value (0). When you write score = 10, you are peeling the label off 0 and sticking it on 10. The equals sign in Python is an assignment — it moves a label — not a statement that two things are the same. This is why score = score + 5 makes sense in Python but would be nonsense as a maths equation: it means "move the score label to whatever score + 5 is right now".

    Variables make programs flexible. Without them, every piece of information would have to be written directly into the code, and changing one thing would require changing it everywhere. With variables, you change the label once and every part of the program that uses that name immediately sees the new value.

  2. A worked example: a score counter

    Open a text editor and type this small program: score = 0, then score = score + 10, then score = score + 5, then print(score). Run it with python3 filename.py. Python prints 15. Each line reads the current value of score, adds something, and stores the result back under the same name. The print at the end shows the final value.

    Now change the first line to score = 100 and run the program again. Python prints 115 — without changing any other line. This is why variables matter: one change at the top ripples through the entire program automatically, which is exactly the kind of thinking that scales from a ten-line program to a thousand-line one.

  3. The three data types beginners meet first

    Python has three types that appear immediately in beginner programs. An integer (int) is a whole number: score = 0, lives = 3. A string (str) is text, always inside quotes: name = "Alex", message = "Game over". A boolean (bool) holds only True or False: is_playing = True, game_over = False. Python chooses the type based on how the value is written — no quotes means a number, quotes means text, True or False means a boolean.

    Understanding which type a value has explains most beginner errors. The expression "3" + "5" in Python gives "35", not 8, because both values are strings and Python joins them like words. The expression 3 + 5 gives 8 because both are integers. If a child types age = "10" and then tries age + 1, Python raises a TypeError — it cannot add a string and an integer. Converting with int(age) + 1 fixes it immediately.

  4. Where variables fit in the bigger picture

    Variables are the building block that makes everything else in programming possible. Loops use a variable to count how many times they have run. Functions take values in through variables called parameters and send results back through a return value. Lists are variables that hold many values at once instead of one. Every program your child writes from here on will use variables in every few lines.

    The most important habit to build now is reading error messages carefully rather than changing things at random. A NameError — "name 'score' is not defined" — means the program used a name before creating it. A TypeError means the wrong kind of value was used somewhere. These messages tell you exactly what went wrong and where, which is a faster path to fixing the problem than guessing.

Signs it’s time for outside help

When home help has done what it can

  • Uses the equals sign to check whether two things are equal, instead of == (the comparison operator).
  • Creates a variable with a space in the name, like player name = "Alex", and cannot understand the SyntaxError.
  • Tries to add a string and an integer without converting first, and cannot explain why the TypeError appeared.
  • Changes a variable in one place and is surprised that the original value is gone — does not yet have a mental model of "label moving".
  • Uses single-letter names like x and y everywhere, then cannot read their own code five minutes later.

Questions parents ask

FAQ

What is the difference between = and == in Python?

= is assignment: it makes a name point to a value (score = 10). == is comparison: it checks whether two values are equal and gives True or False (score == 10 gives True if score is 10, False otherwise). Mixing them up is one of the most common beginner mistakes and produces either a syntax error or the wrong result.

Does Python care whether a variable holds a number or text?

Yes. Python tracks the type of every value, and some operations only work on certain types. Adding two integers gives a number; adding two strings joins them as text; trying to add a string and an integer raises a TypeError. The type() function shows what kind of value a variable currently holds.

What age do children usually learn about variables in Python?

Most children encounter variables in their first Python lesson, typically around ages 9–13 (Grades 4–8). The concept itself is not age-restricted — younger children can understand labelled boxes — but the usefulness becomes clearer once a program is long enough to need several values at once.

Can a variable hold different types of values at different times?

Yes. In Python, score = 0 makes score an integer, but score = "ten" later in the same program makes it a string. Python does not prevent this. However, changing a variable's type mid-program is usually a mistake in beginner code and leads to confusing errors, so it is worth noting when it happens.

Not sure which is right for your child?

Tell us their age and what they have tried so far, and we will suggest where to start before you book anything.

Keep reading