GCSE · Computer Science · Edexcel · Spec 1CP2
Primitive data types
Type 1. Type 2. Ask the program to add them. Out comes 12. Your computer isn't broken, so what on earth does it think it's looking at?
Computer Science · Data types
Why does 1 + 2 make 12?
Same two inputs, run twice. You type 1, then 2. Step through and watch what each variable is really holding.
Before you step on: you type 1 and then 2. What do you reckon Version A prints?
1 # Version A: no casting2 num1 = input()3 num2 = input()4 print(num1 + num2)5 # Version B: cast with int6 num1 = int(input())7 num2 = int(input())8 print(num1 + num2)
| num1 | num2 |
|---|---|
| "1" · string |
Output
Step 1: You typed a number, but input() hands it back as a string. So num1 holds the text 1, not the number 1.
Keep an eye on the type written beside each value. That's where the whole story is.
Computer Science · Data types
Which data type is it?
Pick a value, then choose the data type you think it belongs to. Two of them are sneakier than they look.
Still to sort
Integer (0)
Whole numbers.
Where the line is: No decimal part. If it has a decimal part, it's real.
Real (floating point) (0)
Decimal numbers.
Where the line is: A decimal number stays real even when the decimal part is .0.
Boolean (0)
True or False.
String (0)
Text, and it can also hold numbers, characters and symbols.
Where the line is: Several characters, or a number that was typed into input(), go here.
Char (character) (0)
A single character.
Where the line is: One character only. Text of several characters is a string.
Predict, then check
Someone wanted whole numbers but reached for float().
The program has num1 = float(input()) and num2 = float(input()), then prints num1 + num2. You type 3, then 3. Commit to an answer: what prints?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- A data type is the kind of data a computer can store, plus the actions you can perform on it.
- Types keep data stored and processed correctly. For example, you can't do calculations with strings.
- Integer stores whole numbers, like 3. Real (floating point) stores decimal numbers, like 5.3.
Have a goA shop till stores a price of 7.25. Integer or real (floating point)?
Real (floating point).
It has a decimal part, and integers store whole numbers only, so it can't be an integer.
- Boolean holds True or False. String holds text, and can also hold numbers, characters and symbols.
- Char (character) is a single character, like a. It's a general data type: Python holds one character as a string.
Have a goPriya is very sure 'banana' is a char because it's made of letters. Which data type actually fits, and where has she slipped?
String. A char is one character and 'banana' has six.
A char holds a single character, like a. Text made of several characters is a string, however letter-y it looks.
- Here's the catch: input() returns a string in Python, even when the user types a number. A typed 15 is a string.
Have a goYou type 15 into a program that uses input(). Can it do calculations with that 15 exactly as it arrives?
No. It arrives as a string, not a number.
input() returns a string even when you type a number, and you can't do calculations with strings.
- Casting converts a value to another data type: str() gives a string, int() an integer, float() a real number.
- Add two uncast inputs and the strings get joined: 1 and 2 gives 12. Cast each with int() and you get 3.
- Use float() when you wanted a whole number and you get a decimal: 5 comes out as 5.0, and 3 plus 3 as 6.0.
- Casting isn't a force field. With int(), typing a word such as four causes an error that crashes the program as it runs.
The big picture
Every value has a data type, and the type decides what the computer can do with it. In Python, input() always hands back a string, so adding two uncast inputs joins them instead of adding them. Casting with int(), float() or str() changes the type, but it can't rescue an input that can't be converted.
Key points
Worked example
Problem
A game asks for a whole-number score, then adds 10 to it. The user types 15. Work out what input() gives back, what to change, and what the program then calculates.
⚠ Watch out
Treating a number typed into a program as if it's already a number. It arrives as a string, so it has to be cast before it can be used in a calculation.
Memory hook
input() hands you text. Cast it before you count with it.
Check yourself
A user types 20 into num = input(). What data type is num, and what one change would let you add 5 to it?
Flashcards
(14)What is a data type?
Why do programs bother with data types?
Integer
Real (floating point)
Boolean
String
Char (character)
What data type does input() return in Python?
What is casting?
Which Python functions cast to a string, an integer and a real number?
What does num1 = int(input()) do?
What happens if you add two uncast inputs?
What do you get if you use float() when you wanted a whole number?
Can an int() cast still go wrong?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
- CSV file I/O
- Decomposition and abstraction in programming
- Evaluating program fitness and efficiency
- Functions vs procedures
- Global vs local variables
- Identifying and correcting program errors
- Programming – condition-controlled repetition
- Programming – count-controlled repetition
- Programming – iteration over data structures
- Programming – selection
- Programming – sequencing
- Programming arithmetic operators
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 24 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.