GCSE · Computer Science · AQA · Spec 8525
String data type
Give a program 12 and 34 to add, and it proudly prints 1234. Broken? No: it did exactly what it was told. Let's find out why.
Computer Science · Watch it happen
The program that joins instead of adds
Two values made of digits go in. Step through one line at a time and watch the table. The top half stores them as strings; the bottom half turns them into integers.
Before you press Next: what do you think line 4 will print?
1 a ← "12"2 b ← "34"3 joined ← a + b4 OUTPUT joined5 x ← STRING_TO_INT(a)6 y ← STRING_TO_INT(b)7 total ← x + y8 OUTPUT total
| a | b | joined | x | y | total |
|---|---|---|---|---|---|
| "12" |
Output
Step 1: a holds the string "12". The quotation marks tell the program this is text: the character 1 followed by the character 2. It is not the number twelve.
Press Next one line at a time. Before each step, predict what will appear in the table.
Your turn · Choosing a data type
String or number? You decide
Should each piece of data be stored as a string, or as a number type?
Still to sort
Store as a string (0)
Text to keep exactly as written. Nobody does sums with it.
Where the line is: Digits alone don't make something a number. If the program will never add, subtract or average it, and every character has to survive exactly as typed, it's a string.
Store as a number type (0)
An amount the program calculates with (an integer or a real).
Where the line is: If the program has to do arithmetic with it, like adding it up, counting with it or comparing sizes, it needs a number type.
Real programs have to make this choice for every piece of data. Pick an item, choose where it goes, then read why.
AQA exams use the general type names integer, real, Boolean, character and string. Write "string", not a language's own name such as str.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Why a program can decide that 12 + 34 = 1234, and why it isn't wrong.
What you need to know
- What a data type is, and why it decides what a program can do with a value
- What a string is: a sequence of characters of any kind, treated as text
- How to decide when data should be stored as a string
- What can go wrong when data is stored as the wrong type
The big picture
A data type tells a program what kind of value it is holding, and that decides what the program can do with it. A string is a sequence of characters (letters, digits, spaces or symbols) treated as text. Use a string for data you keep exactly as written and never calculate with, like names, phone numbers and postcodes. Using the wrong type can cause errors: + may join strings instead of adding them, leading zeros can be lost, and some programs stop altogether.
Key points
Worked example
Problem
A cinema program asks how many adult tickets and how many child tickets a customer wants. The customer types 2 and then 1, but the program says the total is 21 tickets. Here is the code: adults ← USERINPUT children ← USERINPUT tickets ← adults + children OUTPUT tickets In this language, anything typed at the keyboard is read in as a string. Find the problem and fix it.
⚠ Watch out
Thinking a value made only of digits must be a number. A PIN such as 0417 is all digits, but you'd never add two PINs together, and stored as an integer it would become 417. Digits don't decide the type. What the program will do with the data decides it.
Memory hook
Ask one question: will I do sums with it? If not, and it has to stay exactly as written, it's a string. And remember: in quotation marks, + sticks digits together, so "10" + "10" is "1010" in Python and our pseudocode.
Check yourself
From memory: what does OUTPUT "25" + "25" display in this lesson's pseudocode, and what would 25 + 25 display? Should a locker code like 0093 be a string or a number type, and why?
Flashcards
(11)What is a data type?
What is a string?
Can a string contain digits?
How can you usually spot a string value in code?
In Python or this lesson's pseudocode, what does + do with two strings?
Which question decides whether data should be a string?
Why is a phone number stored as a string rather than an integer?
What goes wrong if quantities are stored as strings and added with +?
What happens in Python if you try "12" + 5?
Name four common data types.
Python calls its string type str. What is the general name?
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 AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)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 29 September 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.