AQA 7517, section 4.1.1.1
A data type tells the computer what kind of value a variable holds, how much memory it needs, and which operations make sense on it. You can add two numbers, but adding two Boolean values or subtracting one name from another makes no sense. Choosing the right type makes programs correct, efficient and easier to read.
The built-in data types
| Data type | Holds | Example value |
|---|---|---|
| Integer | Whole numbers | 17, -4 |
| Real / float | Numbers with a fractional part | 4.99, -0.5 |
| Boolean | True or false | True |
| Character | A single symbol | "A" |
| String | A sequence of characters | "Hello" |
| Date/time | A date, a time, or both | 2026-11-15 |
| Pointer / reference | The memory address of another value | (see below) |
| Record | Several related fields, which can have different types | A student |
| Array | A fixed-size, indexed collection of items of one type | [3, 8, 1] |
Integer
Integers are whole numbers. They have exact values, so use them for counting, indexing and anything that can't be fractional.
age = 17
print(7 // 2) # 3 integer division
print(7 % 2) # 1 remainder
print(7 / 2) # 3.5 ordinary division gives a real in Python
Real / float
A real (floating point) number stores values with a fractional part. They are stored in binary, so many decimal fractions can only be approximated.
price = 4.99
print(0.1 + 0.2) # 0.30000000000000004
Because of this, never test two floats for exact equality. For money, many programs store whole pence as an integer instead (499 rather than 4.99), which avoids rounding errors. The reason is covered in the notes on binary and floating point.
You can convert between types, which is called casting:
int("42") # 42
float("3.5") # 3.5
str(12) # "12"
int(3.9) # 3 the fractional part is cut off, not rounded
Boolean
A Boolean has only two values, true and false. Conditions in if statements and loops produce Booleans.
is_member = True
print(5 > 3) # True
print(5 == 3) # False
Character and string
A character is a single symbol, and a string is a sequence of characters. Each character is stored as a number, from a character set such as ASCII or Unicode.
print(ord("A")) # 65
print(chr(66)) # B
word = "Hello"
print(len(word)) # 5
print(word[0]) # H
print(word[1:3]) # el
print(word + " world") # Hello world
Python has no separate character type, so a character is just a string of length 1. Many other languages do have one. Strings in Python are immutable, meaning you can't change a character in place: word[0] = "J" is an error, and you build a new string instead.
Phone numbers and postcodes should be strings, even though a phone number looks numeric. You never do arithmetic on them, and a leading zero would be lost in an integer.
Date/time
Dates and times have their own type because they have special rules: months of different lengths, leap years and clock arithmetic. A date/time type lets you compare and subtract them correctly.
from datetime import date
deadline = date(2027, 6, 10)
today = date(2026, 11, 15)
print((deadline - today).days) # 207
Pointer / reference
A pointer or reference stores the memory address of a value rather than the value itself. It is used when a value is created at runtime ("dynamically"), such as an object or a node in a linked list, so the program needs a way to find it.
Not every language has explicit pointers. Python doesn't let you work with raw addresses, but every variable holding an object is really a reference to it. That causes behaviour you need to understand:
a = [1, 2, 3]
b = a # b refers to the SAME list, not a copy
b.append(4)
print(a) # [1, 2, 3, 4]
c = a.copy() # c is a NEW list
c.append(5)
print(a) # still [1, 2, 3, 4]
Assigning b = a copies the reference, so both names point to one list. Changing it through one name changes what the other sees. In languages with explicit pointers, you would store an address, dereference it to reach the value, and be responsible for making sure it points somewhere valid.
Common mistake: thinking b = a makes a copy. It makes a second name for the same object. Use .copy() (or the language's equivalent) when you need an independent copy.
Record
A record groups related values, called fields, into one item. The fields can have different data types. A student record might have a name (string), an age (integer) and a flag for membership (Boolean).
Python has no built-in record type, so a dictionary can be used as the equivalent, with the field names as its keys.
student = {
"name": "Sam",
"age": 17,
"year_group": 13,
"is_member": True,
}
print(student["name"]) # Sam
student["age"] = 18 # fields can be changed
Unlike a true record, a dictionary doesn't fix which fields exist or what type each one holds, so you have to keep the field names and types consistent yourself.
Array
An array is a fixed-size collection of items of the same type, stored next to each other in memory and reached by an index. A one-dimensional array is like a row of boxes; a two-dimensional array is a table of rows and columns.
Python has no built-in array type, so we use a list as the equivalent. A Python list behaves like an array when you read and change items by index, but it can also change size.
scores = [12, 7, 19]
print(scores[0]) # 12 Python indexes start at 0
scores[1] = 8
grid = [[0, 0, 0],
[0, 0, 0]]
grid[1][2] = 5 # row 1, column 2
Array or list?
| Array | List | |
|---|---|---|
| Size | Fixed when it is created | Can grow and shrink |
| Item types | All the same type | Can be mixed (in Python) |
| Storage | One block of memory, so any item can be reached directly by index | Depends on how it is implemented |
| Adding or removing items | Not possible without making a new array | Built in, such as append and pop |
In exam answers about arrays, assume the array has a fixed size and holds one type of data, unless the question says otherwise.
The difference between static data structures (such as arrays) and dynamic ones (such as lists) is covered in 4.2.1.4, abstract data types.
User-defined data types
A user-defined data type is one you build yourself from the built-in types. A record type, such as a student record with the fields above, is the most common example. In Python, you define your own type with a class:
class Student:
def __init__(self, name, age, is_member):
self.name = name
self.age = age
self.is_member = is_member
s = Student("Sam", 17, True)
print(s.name) # Sam
Student is now a type of its own, built from a string, an integer and a Boolean, and you can make as many student values as you need. Defining your own types makes code clearer, because related data is kept together under one meaningful name. Classes are covered in more detail in object-oriented programming (4.1.2.3).
Choosing a data type
| Data | Best type | Why |
|---|---|---|
| Number of items in a basket | Integer | Always whole |
| Height in metres | Real | Has a fractional part |
| Whether a user is logged in | Boolean | Only two possibilities |
| A person's initials | String | Several characters |
| A mobile phone number | String | Not used in arithmetic, and keeps the leading zero |
| Date of birth | Date | Allows age calculations |
| A student's details | Record | Fields of mixed types together |
| Marks for 30 students | Array | Many values of one type, reached by index |
Try it
Choose the best data type for (a) a person's age, (b) a username, (c) whether a form has been submitted
(a) Integer, because ages are whole numbers. (b) String, because it is a sequence of characters. (c) Boolean, because there are only two possibilities.
What does this print? a = [1, 2, 3]; b = a; b[0] = 99; print(a)
It prints [99, 2, 3]. The assignment b = a copies the reference, so a and b are the same list, and the change shows up through both names.
Why might 0.1 + 0.2 not equal exactly 0.3 in a program?
Real numbers are stored in binary, and 0.1 and 0.2 can't be written exactly as binary fractions. They are stored as close approximations, and the small errors show up in the result.