Data Types in Programming: KS3 Computing Guide

In programming, a data type tells the computer what kind of data a variable holds and what operations are valid on it. At KS3, students meet four core types: integer, float, string, and Boolean. Choosing the wrong type — or mixing types carelessly — is one of the most frequent sources of errors in Python programs.

What is a data type and why does it matter?

Think of a data type as the label on a storage box that tells you what kind of content it is allowed to hold. An integer box can only hold whole numbers; a string box holds text; a Boolean box holds only one of two possible values: True or False.

The data type matters for three reasons:

Memory allocation — the computer reserves different amounts of memory for different types. An integer typically needs 4 bytes; a long piece of text needs far more.

Valid operations — you can multiply two integers, but multiplying two strings is meaningless. Knowing the type tells you what operations make sense.

Error prevention — attempting an invalid operation (adding a number to a string) causes a TypeError in Python. Understanding types helps you avoid this class of bug entirely.

What is an integer?

An integer (int) is a whole number with no decimal point. It can be positive, negative, or zero.

score = 0
year = 2026
temperature = -5
num_players = 4

Integers support all the standard arithmetic operations: +, -, *, /, // (integer division), % (remainder), and ** (power).

total = 15 + 7 # 22
remainder = 15 % 4 # 3 (15 divided by 4 leaves remainder 3)
power = 2 ** 8 # 256

Note that dividing two integers in Python 3 with / always returns a float, even if the result is whole. Use // (floor division) to keep the result as an integer: 15 // 4 gives 3.

What is a float?

A float (float) is a number that can contain a decimal point. The name comes from "floating-point", the way computers represent non-integer values.

height = 1.75
pi = 3.14159
temperature = 36.6
average = 78.5

Floats are used whenever precision beyond whole numbers is required — measurements, averages, percentages, and scientific values. Be aware that floats can have tiny rounding errors:

print(0.1 + 0.2) # Output: 0.30000000000000004

This is a known limitation of how binary floating-point arithmetic works, not a Python bug. At KS3, it is worth knowing it exists, though you rarely need to deal with it at this level.

What is a string?

A string (str) is a sequence of characters enclosed in quotes. It stores text data of any kind: words, sentences, even digits that you are treating as text.

name = "Professor Turing"
postcode = "WC2N 5DU"
reply = 'yes'
empty = ""

You can use either single quotes (') or double quotes (") in Python, as long as you are consistent within a single string. Strings support operations like concatenation (joining) and repetition:

first = "Alan"
last = "Turing"
full = first + " " + last # "Alan Turing"
divider = "-" * 20 # "--------------------"

Note that "42" and 42 are completely different in Python: the first is a string, the second is an integer. You cannot add them directly.

What is a Boolean?

A Boolean (bool) is the simplest data type of all — it stores one of exactly two values: True or False. Booleans are named after the mathematician George Boole, whose logic system underpins all digital computing.

logged_in = True
game_over = False
is_adult = age >= 18 # True if age is 18 or more, False otherwise

Booleans are the result of any comparison (==, !=, <, >, <=, >=) and are used directly in if statements and while loops. Every condition in a program ultimately evaluates to True or False.

How do you cast between data types?

Type casting (also called type conversion) means converting a value from one data type to another. In Python, four built-in functions handle the most common casts:

Function | Converts to | Example | Result
int() | Integer | int("42") | 42
float() | Float | float("3.14") | 3.14
str() | String | str(99) | "99"
bool() | Boolean | bool(0) | False

The most important cast at KS3 is converting user input to a number. The input() function in Python always returns a string, even if the user types digits:

age = input("Enter your age: ") # age is a string, e.g. "14"
age = int(input("Enter your age: ")) # age is an integer, e.g. 14

Without the cast to int, any arithmetic on age will cause a TypeError.

A worked example: age calculator

name = input("What is your name? ")
birth_year = int(input("What year were you born? "))

current_year = 2026
age = current_year - birth_year

print("Hello, " + name + "!")
print("You are approximately " + str(age) + " years old.")

if age >= 18:
print("You are an adult.")
else:
print("You are not yet an adult.")

Tracing through with name = "Rina", birth_year = 2012:

Variable | Type | Value
name | str | "Rina"
birth_year | int | 2012
current_year | int | 2026
age | int | 14

The str(age) cast on line 7 converts 14 to "14" so it can be concatenated with the surrounding strings. Without it, Python raises TypeError: can only concatenate str (not "int") to str.

Frequently asked questions

What are the four main data types at KS3?

The four main data types taught at KS3 are: integer (int) for whole numbers, float (float) for decimal numbers, string (str) for text, and Boolean (bool) for True or False values. Most KS3 exam questions and programming tasks draw exclusively on these four types.

Why does Python's input() function return a string?

The input() function reads whatever the user types as raw text. Since the user could type anything — words, numbers, symbols — Python cannot assume a type. It is your responsibility as the programmer to convert the input to the appropriate type using int(), float(), or another casting function before performing operations on it.

What is the difference between an integer and a float?

An integer is a whole number with no decimal component (e.g. 7, -3, 0). A float is a number that can include a decimal point (e.g. 7.0, -3.14, 0.001). Integers are exact; floats can occasionally introduce tiny rounding errors. Use an integer when dealing with whole counts (lives, scores, indices); use a float when precision with decimal places is required (heights, averages, scientific measurements).

What happens when you mix data types in Python?

Python is strongly typed, meaning it does not automatically convert between types. Adding an integer to a string, for example, raises a TypeError: unsupported operand type(s) for +: 'int' and 'str'. The fix is to cast explicitly: convert the integer to a string with str() before concatenating, or convert the string to an integer with int() before doing arithmetic.

For Socratic computing tutoring at KS3 and GCSE — see aitutors.me.