A variable in programming is a named storage location in a computer's memory that holds a value which can change while a program runs. At KS3, variables are one of the first concepts taught in every programming unit — understanding them is essential to writing any program more complex than a single output line.

What does a variable actually do?

Imagine a box with a label on it. The label is the variable's name; the contents of the box is the variable's value. You can look at what is in the box, change what is inside, or use the contents in a calculation — all by referring to the label.

In Python (the most common language in KS3 computing), you create a variable and give it a value using the assignment operator =:

score = 0
player_name = "Aisha"

After these two lines, the computer has reserved space in memory labelled score (containing the integer 0) and player_name (containing the text "Aisha").

The DfE national curriculum for computing requires KS3 students to "use two or more programming languages, at least one of which is textual, to solve a variety of computational problems" and to understand "the use of variables" (gov.uk/government/publications/national-curriculum-in-england-computing-programmes-of-study). Variables are explicitly named as a core concept.

Why are variables called variables?

Because their value can vary — change — during a program's execution. This distinguishes a variable from a constant, which is a named value that never changes.

# Variable — value changes during the game
score = 0
score = score + 10   # score is now 10

# Constant — value is fixed (written in uppercase by convention)
MAX_LIVES = 3

In the example above, score starts at 0 and increases by 10 each time the player earns points. MAX_LIVES is set once and never changed.

Data types: what kinds of value can a variable hold?

At KS3 students learn about four basic data types:

Data type What it stores Python example
Integer (int) Whole numbers age = 14
Float (float) Decimal numbers temperature = 36.6
String (str) Text (characters) name = "Jordan"
Boolean (bool) True or False only logged_in = True

The data type matters because it affects what operations you can perform. You can multiply two integers. You cannot multiply two strings (in most cases). Trying to add an integer and a string causes a type error — one of the most common bugs KS3 students encounter.

age = 14
message = "You are " + age + " years old."  # ERROR: can't add int to string
message = "You are " + str(age) + " years old."  # CORRECT: convert first

A worked example: a score-tracking program

Here is a short program that uses variables to track a player's score in a quiz:

player_name = input("Enter your name: ")
score = 0

answer1 = input("What is 8 x 7? ")
if answer1 == "56":
    score = score + 1
    print("Correct!")
else:
    print("Wrong. The answer is 56.")

answer2 = input("What is the capital of France? ")
if answer2.lower() == "paris":
    score = score + 1
    print("Correct!")
else:
    print("Wrong. The answer is Paris.")

print(player_name + ", your final score is " + str(score) + " out of 2.")

Tracing through this with name = "Sanjay", correct answers for both questions:

Line Variable Value after this line
1 player_name "Sanjay"
2 score 0
4 answer1 "56"
5 score 1 (0 + 1)
9 answer2 "Paris"
10 score 2 (1 + 1)

Output: Sanjay, your final score is 2 out of 2.

Notice how score is updated at runtime — it starts at 0 and grows as the player answers correctly. This is exactly what "variable" means.

Naming variables: rules and conventions

In Python:

  • Variable names must start with a letter or underscore (not a number)
  • Variable names can contain letters, numbers and underscores
  • Variable names are case-sensitive: Score and score are two different variables
  • Variable names cannot be Python keywords like if, while, print

Good naming conventions (not enforced by Python, but expected by teachers and examiners):

  • Use descriptive names: student_age rather than x
  • Use snake_case (words separated by underscores) for multi-word names
  • Use UPPER_CASE for constants: MAX_SCORE = 100

A variable named x or temp tells the reader nothing about what it stores. A variable named total_marks or player_health makes code readable at a glance.

How variables connect to other KS3 computing concepts

Variables do not exist in isolation — they interact with every other programming concept:

  • Algorithms — every algorithm that stores intermediate results needs variables.
  • SelectionIF score > 50 THEN — the condition checks a variable's value.
  • Iteration — loop counters (e.g. counter = counter + 1) are variables that change with each pass through the loop.
  • Decomposition — each sub-problem or function typically has its own set of variables.
  • Data structures — lists, dictionaries and arrays are collections of related variables.

BBC Bitesize (bbc.co.uk/bitesize/guides/zwmbgk7/revision/1) has interactive exercises where students can write and run code that uses variables, which is the fastest way to build intuition for how they work.

Common mistakes KS3 students make with variables

Using a variable before assigning it — in Python this causes a NameError. Always assign a value before using it.

Confusing = (assignment) with == (comparison)score = 10 stores the value 10 in score. score == 10 asks whether score currently equals 10 (True or False). Mixing these up is one of the most frequent bugs at KS3.

Using a string where a number is neededinput() in Python always returns a string. To use it in arithmetic, convert it: age = int(input("Enter your age: ")).

Choosing a name that is too vague — naming a variable data, thing, or x makes code very hard to debug. Descriptive names save time.

Frequently asked questions

What is a variable in programming in simple terms for KS3?

A variable is a named storage location in a computer's memory that holds a piece of data. The value stored can change while the program runs. You give a variable a name (like score or player_name) and then use that name throughout the program to read or update the value.

What are the main data types for variables at KS3?

At KS3 the four main data types are: integer (whole numbers), float (decimal numbers), string (text), and Boolean (True or False). The data type determines what you can do with the variable — for example, you can add two integers but you cannot multiply two strings.

What is the difference between a variable and a constant?

A variable can change its value at any point during a program's execution. A constant is set once at the beginning and never changed. In Python, constants are written in UPPER_CASE by convention (e.g. MAX_LIVES = 3), though Python does not technically enforce this — it is a naming agreement that tells other programmers not to change the value.

Why do I get a TypeError when using variables in Python?

A TypeError in Python usually means you have tried to combine two values of incompatible types — for example, adding an integer and a string. The fix is to convert one value to the right type: use str() to convert a number to a string, or int() to convert a string of digits to an integer.

Do variables work the same way in all programming languages?

The concept of a variable — a named storage location whose value can change — is the same in every programming language. The syntax for creating and using variables differs: Python uses name = value, while some other languages require you to declare the type first. At KS3 you learn the concept using Python, but the same idea applies directly in JavaScript, Java, C# and every other language you might study later.


For Socratic computing tutoring — from variables to full programs — see aitutors.me.