GCSE · Computer Science · AQA · Spec 8525
String concatenation
Computers are brilliant at maths. So what could go wrong when a program puts + between "12" and "30"? Quite a lot, as you're about to see.
Computer Science · Programming
Watch a message grow, one join at a time
Step through the program line by line. The table shows each variable's value after its line runs, and quotation marks show exactly where each string starts and ends, spaces included.
Before you step onto line 3, make a prediction: what exactly will full hold?
1 first = "Ada"2 last = "Lovelace"3 full = first + last4 full = first + " " + last5 msg = "Hello, " + full6 msg = msg + "!"7 print(msg)
| first | last | full | msg |
|---|---|---|---|
| "Ada" |
Output
Step 1: first now holds the string Ada. A string is just a sequence of characters, here A, d and a.
Use Next to run one line at a time, and check your prediction for line 3 before you look.
Predict, then check
Look closely at the quotation marks before you choose.
If a = "12" and b = "30", what does print(a + b) show on the screen?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
How programs build new strings by joining old ones end to end, and why every space and every piece's position is your job.
What you need to know
- Concatenation joins two or more strings end to end to make one new string. In Python, and many other languages, + does this when the values are strings.
- The characters are copied exactly as written and in the order written. No space is added, so join one in yourself: first + " " + last, or put it inside a literal such as "Hello, ".
- Strings made of digits are still text: "12" + "30" gives "1230", not 42.
- You can join literals and string variables in any mix, and msg = msg + "!" stores a longer string back in the same variable.
The big picture
Concatenation means joining strings end to end to make a new string. In Python and many other languages, + does the joining when the values are strings. The characters are copied exactly as written, in the order written, and nothing is added between them, so any space has to be joined in by you. Digits in quotation marks are still text: "12" + "30" gives "1230", not 42. You can mix literals and string variables, and msg = msg + "!" stores a longer string back in msg.
Key points
Worked example
Problem
State exactly what this program prints. Line 1: word = "rain" Line 2: word = word + "bow" Line 3: word = "A " + word Line 4: print(word)
⚠ Watch out
Expecting the computer to put a space between joined words. "Happy" + "birthday" gives "Happybirthday". The space only appears if you join one in: "Happy" + " " + "birthday", or "Happy " + "birthday".
Memory hook
Plus on strings is glue, not maths: what you write is exactly what you get, in the order you wrote it, spaces and all.
Check yourself
Cover the page. What do print("bath" + "room") and print("7" + "7") show? Now store See you soon in note by joining three strings. Where do the spaces go?
Flashcards
(6)What is concatenation?
Does joining two strings add a space between them?
Two ways to get a space between first and last when you join them
What is "4" + "4" when both are strings?
Does the order of the pieces matter in a join?
What does name = name + "!" do?
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.