Data Types and Casting
Aligned to the OCR J277 specification
- Level
- Foundational
- Reading time
- 7 min
- Published
- 11 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- OCR J277 requires five data types: integer (whole numbers), real (decimal numbers), Boolean (True/False), character (single symbol), and string (sequence of characters).
- Casting converts a value to a different type using functions such as int(), float(), str(), and bool() - the original variable's type is not changed.
- User input from input() is always returned as a string in Python, so it must be cast with int() or float() before arithmetic can be performed.
- A common mistake: int(3.9) gives 3, not 4 - casting to integer truncates toward zero and does not round.
- Choosing the wrong type causes errors: storing a price such as 3.99 as an integer loses the decimal part; storing a name as an integer is impossible.
Studying this for an exam?
Generate a personalised learning path for this subject. Free to get started.
Key terms
- Integer
- A data type that stores whole numbers, positive or negative, with no decimal point, such as 0, 42, or -7.
- Real
- A data type (called float in Python) that stores numbers with a decimal fractional part, such as 3.14 or -0.5.
- Boolean
- A data type that holds exactly one of two values: True or False. Used in conditions and comparisons.
- Character
- A data type that stores a single symbol - a letter, digit, punctuation mark, or space.
- String
- A data type that stores an ordered sequence of zero or more characters, used for text such as names and messages.
- Casting
- Converting a value from one data type to another using a function such as int(), float(), or str(). The conversion produces a new value and does not change the original variable.
- Truncation
- What happens when int() is applied to a real number: the decimal part is dropped (not rounded), so int(3.9) gives 3.
Frequently asked questions
Integer stores whole numbers with no decimal point, used for things that are counted such as lives or scores. Real stores numbers with a decimal part, used for measurements or prices such as 3.99.
Casting converts a value from one data type to another, producing a new value of the target type. For example, int("42") converts the string "42" to the integer 42, and str(100) converts the integer 100 to the string "100".
The input() function always returns a string. Adding a string and an integer causes a TypeError, so you must call int() or float() on the result first - for example: age = int(input("Enter age: ")).
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Programming Fundamentals
String Manipulation and File Handling
Related lessons
6 min
6 min
6 min
7 min