GCSE Computer Science

Python variables and data types โ€” GCSE Computer Science

What is a variable?

A variable is a name that holds a value. When the value changes, the name stays the same. That's all a variable is โ€” a label attached to a piece of data so you can refer to it later.

The reason variables matter in GCSE Computer Science isn't philosophical. It's practical: without variables, a program can't remember anything. Every piece of data that a program stores, processes, or outputs lives in a variable at some point.

Data types

age = 16          # integer
name = "Alice"    # string
height = 1.65     # float
is_enrolled = True  # boolean

Python assigns a data type automatically based on the value. An integer is a whole number. A float is a decimal number. A string is text โ€” always wrapped in quotes. A boolean is either True or False. GCSE exams expect you to identify the correct data type for a given situation and explain why.

Type casting

age = input("Enter your age: ")  # age is a string
age = int(age)                   # now age is an integer
print(age + 1)

input() always returns a string โ€” even if the user types a number. To do arithmetic with it, you need to convert it. int() converts to an integer. float() converts to a decimal. str() converts back to a string. Getting this wrong is one of the most common causes of runtime errors in GCSE exam answers.

What examiners actually test

Variable questions appear in three forms: identifying the data type of a given value, explaining what a variable stores at a specific point in a program (often as part of a trace table), and correcting a type error in given code. The casting question โ€” where input() returns a string that needs converting before arithmetic โ€” appears so consistently it is worth memorising as a pattern.

Want structured Python lessons? Python Coach covers variables, data types, and 25 other lessons with 195 challenges โ€” free 60 teaching day trial.

Start learning →