GCSE · Computer Science · Edexcel · Spec 1CP2
Primitive data types
Type 1, then 2, ask the program to add them, and out comes 12. What does the computer think it is 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 holding.
Before you step on: you type 1 and then 2. What do you think 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.
Compare the type written beside each value in Version A and Version B.
Computer Science · Data types
Which data type is it?
Pick a value, then choose the data type you think it belongs to. Watch the tricky ones.
Still to sort
Integer (0)
Whole numbers.
Where the line is: No decimal part. If it has a decimal part, it is 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
A learner wanted whole numbers but used float().
The program has num1 = float(input()) and num2 = float(input()), then prints num1 + num2. You type 3, then 3. 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.
- Programs use data types so data is 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 till stores a price of 7.25. Does that fit integer or real (floating point)?
Real (floating point).
It has a decimal part, and integers store whole numbers only.
- 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 a single character as a string.
Have a goPriya insists 'banana' is a char because it's made of letters. Which data type fits better, and why is she wrong?
String. A char is one character and 'banana' is six.
A char holds a single character, like a. Text of several characters is a string.
- input() returns a string in Python, even when the user types a number. So 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 cannot do calculations with strings.
- Casting converts a value from one data type to another: str() gives a string, int() an integer, float() a real number.
- Add two uncast inputs and the strings are joined: 1 and 2 gives 12. Cast each with int() and you get 3.
- Using float() when you wanted a whole number gives a decimal: entering 5 outputs 5.0, and adding 3 and 3 outputs 6.0.
- Even with int(), typing a word such as four causes an error that crashes the program when it runs.
The big picture
Every value has a data type, and the type decides what the computer can do with it. 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 won't rescue an input that can't be converted.
Key points
Worked example
Problem
A game asks for a whole-number score and then needs to add 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 already being 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 use 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
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 9 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.