Every piece of data stored in a program has a data type — it tells the computer how to store it in memory and what operations can be performed on it. Using the wrong data type causes errors: you can't multiply a string, and you can't store a decimal in an integer without truncation.
The OCR J277 Data Types
Integer
Whole numbers (positive, negative, or zero). No decimal point.
Examples: 0, 42, -7, 1000
Real / Float
Numbers with a decimal point. Also called 'real' in OCR J277.
Examples: 3.14, -0.5, 9.81, 1.0
Boolean
Can only store True or False. Used in conditions and flags.
Examples: True, False
Character (Char)
A single character enclosed in single quotes.
Examples: 'A', '5', '!', ' '
String
A sequence of zero or more characters. Enclosed in double quotes.
Examples: "hello", "Alice", "123"
Data Types — Comparison Table
Data type
What it stores
Memory
OCR example
Integer
Whole numbers, no decimal
Typically 4 bytes
age = 16
Real/Float
Numbers with decimal point
Typically 8 bytes
price = 9.99
Boolean
True or False only
1 bit (1 byte typical)
passed = True
Character
Single character
1–4 bytes (Unicode)
grade = 'A'
String
Sequence of characters
Variable
name = "Bob"
Type Casting — Converting Between Types
Sometimes you need to convert between data types. OCR J277 pseudocode uses these casting functions:
Function
Converts to
Example
Result
int(x)
Integer
int("42")
42
float(x)
Real/float
float("3.14")
3.14
str(x)
String
str(100)
"100"
bool(x)
Boolean
bool(1)
True
ord(c)
ASCII code (integer)
ord('A')
65
chr(n)
Character
chr(65)
'A'
Common Use Cases
// Getting input and converting userInput = input("Enter your age: ") // input() always returns a string age = int(userInput) // convert to integer for arithmetic
// Building a message with concatenation score = 95 OUTPUT"Your score is: " + str(score) // must convert int to string
// Boolean use case gameOver = False IF lives == 0THEN
gameOver = True END IF
String vs Integer — "123" vs 123
The value "123" (string) is NOT the same as 123 (integer). The string is stored as three characters. You cannot do arithmetic on it. If a user types a number into an input() box, it arrives as a string — you must use int() to convert it before arithmetic.
Exam tip: A very common exam question is "State the most appropriate data type for..." followed by a scenario. Key rules: age, score, quantity = integer. Price, weight, percentage = real/float. Yes/no, on/off, pass/fail = Boolean. Single letter/symbol = character. Name, address, message = string. Also know that input() always returns a string in most languages — you must cast it.
⚠️ Common Mistakes
Saying "123" (string) is the same data type as 123 (integer) — they are NOT
Using a real/float for something that should be an integer (e.g. number of students)
Confusing character (single char) and string (multiple chars) — 'A' vs "A"
Forgetting to convert input() from string before doing arithmetic
Saying Boolean stores 0 and 1 — it stores True and False (even if implemented as 0/1)
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
Worksheet — 2.2.1b Data Types
8 questions · 20 marks
Q1State the five data types you need to know for OCR J277 and give one example value for each.[5]
✅ Mark scheme
One mark each for name + valid example: Integer (42) [1]; Real/float (3.14) [1]; Boolean (True/False) [1]; Character ('A') [1]; String ("hello") [1].
Q2State the most appropriate data type for each: (a) A student's name (b) A test score out of 100 (c) Whether a door is locked (d) The price of an item (e) A single grade letter[5]
Q3A program asks the user to input their age. The input() function returns a string. Write the pseudocode to get and convert this input correctly.[2]
✅ Mark scheme
userInput = input("Enter your age: ") [1]; age = int(userInput) [1] (or in one line: age = int(input("Enter your age: ")))
Q4Explain why the statement OUTPUT "Score: " + score causes an error if score is an integer.[2]
✅ Mark scheme
You cannot concatenate (join) a string and an integer using + [1]. The integer must first be converted to a string using str(score) before concatenating: "Score: " + str(score) [1].
Q5What is the difference between the integer 42 and the string "42"?[2]
✅ Mark scheme
The integer 42 is stored as a numeric value and arithmetic can be performed on it (e.g. 42 + 8 = 50) [1]. The string "42" is stored as two characters ('4' and '2') and arithmetic cannot be performed on it — "42" + "8" = "428" (concatenation) [1].
Q6What does ord('Z') return and what does this tell us?[2]
✅ Mark scheme
ord('Z') returns 90 [1]. This is the ASCII code (integer value) for the character 'Z' — each character has a unique numeric code. chr(90) would return 'Z' [1].
Q7Why would you use a Boolean rather than a string to store whether a user has logged in?[1]
✅ Mark scheme
A Boolean (True/False) uses less memory than a string and is more efficient for a two-state condition [1]. It can be directly used in IF conditions without string comparison. Also avoids typos (e.g. "Ture").
Q8A program stores the number of goals scored in a football match. Should it use integer or real? Justify your answer.[1]
✅ Mark scheme
Integer [1] — you cannot score half a goal; goals are whole numbers. Using a real/float would waste memory and allow impossible values like 1.5.
?
out of 20 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 9
Click to reveal definition
🎉
Complete!
Term
Definition
🎯
Mini Test — 2.2.1b Data Types
10 questions · 10 marks · 10 minutes
⏱ 10:00
10 marks
Section A — Multiple Choice [5 marks]
Q1What data type should be used to store a person's height in metres (e.g. 1.75)?
Q2A Boolean variable can store which values?
Q3What does int("25") return?
Q4What is the difference between a character and a string?
Q5What does ord('A') return?
Section B — Short Answer [5 marks]
Q6State the most appropriate data type for each: (a) number of items in a basket (b) temperature in Celsius (c) whether an alarm is active
Mark scheme(a) Integer — whole number of items [1]. (b) Real/float — temperature can be decimal e.g. 36.6°C [1]. (c) Boolean — alarm is either active or not (True/False) [1].
Q7Explain why you must use int() when processing a number entered by the user via input().
Mark schemeinput() always returns data as a string [1]. Arithmetic cannot be performed on strings, so it must be converted to an integer using int() before calculations [1].
Q8A programmer stores a phone number as an integer. Give one problem with this.
Mark schemeAny valid problem: leading zeros are dropped (e.g. 07700 becomes 7700) [1]; cannot store spaces, hyphens or + signs used in international numbers [1]; arithmetic (like addition) doesn't make sense for a phone number [1].
Q9What is type casting? Give one example.
Mark schemeType casting is converting a value from one data type to another [1]. E.g. int("42") converts the string "42" to the integer 42; str(100) converts integer 100 to string "100" [1].
Q10What is the result of "10" + "20" in a programming language? Explain why.
Mark scheme"1020" [1]. Both values are strings, so + performs concatenation (joining) not addition. To get 30, both must be converted to integers first: int("10") + int("20") [1].