AQA GCSE Computer Science (8525), section 3.2.1 (Data types)
What is a data type?
A data type tells the computer what kind of data a value is, and so how much memory it needs and what you can do with it. Every variable and constant has a data type.
The five data types
| Data type | What it stores | Examples |
|---|---|---|
| Integer | a whole number | 7, -30, 0 |
| Real | a number with a decimal part (also called float) | 3.14, -0.5, 2.0 |
| Boolean | one of two values, True or False | True, False |
| Character | a single letter, digit or symbol | 'A', '7', '?' |
| String | text: a sequence of characters | "Hello", "AB12", "" |
Depending on the programming language, these types may have other names (for example real numbers may be called float). In the exam the general names above are used.
Choosing a data type
| Data | Best type | Why |
|---|---|---|
| Number of players | integer | always a whole number |
| Price of an item | real | has pence |
| Whether the user is logged in | Boolean | only two possibilities |
A grade such as B |
character | one symbol |
| A name | string | text of any length |
| A telephone number | string | you do not calculate with it, and it can start with 0 |
In Python
players = 4 # int (integer)
price = 2.99 # float (real)
logged_in = True # bool (Boolean)
grade = "B" # str with one character (character)
name = "Aisha" # str (string)
print(type(players), type(price), type(logged_in), type(name))
Python has no separate character type: a character is a string of length 1.
Why it matters
- Different types can be used in different ways: you can add two integers, but not multiply two Booleans sensibly.
"5" + "5"joins two strings to give"55", whereas5 + 5gives10.- Using a suitable type makes programs more reliable and uses less memory.
Common mistake: storing a number in a string and then wondering why it will not add up. Also, "7" (a string, in quotes) is not the same as 7 (an integer).
Exam tip: when asked for a data type, look at what the data is used for. Telephone numbers and postcodes are usually strings, as you never do arithmetic with them.
Check yourself
Which data type would be best for storing whether a door is open?
Boolean.
What is the data type of 3.0?
Real.
Why is a telephone number stored as a string rather than an integer?
It is not used in calculations, and an integer would lose a leading 0.