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 + b
4 OUTPUT joined
5 x ← STRING_TO_INT(a)
6 y ← STRING_TO_INT(b)
7 total ← x + y
8 OUTPUT total
abjoinedxytotal
"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.

1 / 8

Press Next one line at a time. Before each step, predict what will appear in the table.

Step 1 of 8: 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..

Watch out: "12" and 12 look almost identical on screen. To the program they are different data types, and it treats them completely differently.

Be honest · What's in a string?

What can a string hold?

A program stores each of these values as a string: "Hello", "2024", "Hi there!" and "B7 #4".

Which is closest to what you think right now?
How sure are you?

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.

7 of 7 still to sort.

Real programs have to make this choice for every piece of data. Pick an item, choose where it goes, then read why.

Put it into words

Choose it, then justify it

A quiz app stores each player's username, for example Maz_2011, and their points total, for example 45. (a) State the most appropriate data type for the username and justify your choice. (b) Explain one problem that could happen if the points total were stored as a string. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

UK note

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

1A data type is the kind of value a piece of data is. It decides how the program treats the value and which operations make sense.
2A string is a sequence of characters. Letters, digits, spaces and symbols all count, so "Hi there!", "2024" and "B7 #4" are all strings.
3In code, a string value is usually written inside quotation marks: "12" is a string, while 12 is a number.
4In this lesson's pseudocode, and in Python, + joins (concatenates) two strings instead of adding them: "12" + "34" gives "1234".
5Store data as a string when it must be kept exactly as written and is never used in arithmetic, such as names, phone numbers, postcodes and codes.
6Use a number type for amounts the program calculates with, such as ages, quantities and prices.
7Using the wrong data type can cause errors: wrong results, lost leading zeros, or a program that stops. In Python, for example, "12" + 5 stops the program with a TypeError.
8Common data types include integer, real (floating point), Boolean and string. Languages may give them other names: Python calls its string type str.

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?
The kind of value a piece of data is. It decides how the program treats the value and what it can do with it.
What is a string?
A sequence of characters (letters, digits, spaces or symbols) treated as text.
Can a string contain digits?
Yes. "2024" stored as a string is four characters of text, not the number two thousand and twenty-four.
How can you usually spot a string value in code?
It is written inside quotation marks, like "Hello" or "42".
In Python or this lesson's pseudocode, what does + do with two strings?
It joins them end to end, which is called concatenation. "ab" + "cd" gives "abcd".
Which question decides whether data should be a string?
Will the program do arithmetic with it? If not, and it must be kept exactly as written, use a string.
Why is a phone number stored as a string rather than an integer?
It is never calculated with, and an integer would lose the leading 0 and couldn't hold a space.
What goes wrong if quantities are stored as strings and added with +?
In Python or this lesson's pseudocode they are joined instead of added, so the result is wrong: 12 and 34 give 1234 instead of 46.
What happens in Python if you try "12" + 5?
The program stops with a TypeError, because Python won't join a string to an integer.
Name four common data types.
Integer, real (floating point), Boolean and string.
Python calls its string type str. What is the general name?
String. Languages can use their own names for data types, but the general names are integer, real, Boolean, character and string.

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 posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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.