GCSE · Computer Science · AQA · Spec 8525
String concatenation
Computers are brilliant at maths. So what could possibly go wrong when a program puts + between "12" and "30"? Quite a lot. Stick around.
Computer Science · Programming
Watch a message grow, one join at a time
Step through the program. Each row shows the value a variable holds after that line runs. The quotation marks in the table aren't part of the text; they just show you where each string starts and ends, so you can see every space.
Predict first: after full = first + last runs, what exactly does full hold, spaces and all?
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 holds the string Ada. A string is just a row of characters: A, d, a.
+ copies characters. It doesn't think about what would look nice.
Predict, then check
Look hard at the quotation marks before you choose.
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 sticking old ones end to end, and why every space and every piece's position is your job.
What you need to know
- Concatenation joins strings end to end, in the order you write them, to make one new string.
- Order matters: "top" + "hat" gives tophat, but "hat" + "top" gives hattop.
Have a goYour mate stores a = "dog" and b = "house", then swears print(b + a) shows doghouse. Are they right?
No. b + a shows housedog.
The piece written first comes out first, and b is written first. Only a + b gives doghouse; swapping the order swaps the words.
- Nothing gets added for you. Every space, comma or full stop must be in one of the pieces, exactly once.
Have a goWhat exactly does "ice" + "cream" give, character for character?
icecream, with no space.
Neither piece contains a space, so none appears. Expecting ice cream means expecting + to tidy up the text, and it never does.
- Digits inside quotation marks are text, so they join instead of adding.
Have a goa = "1" and b = "0". What does a + b + a give?
101
All three values are text, so their characters line up in order: 1, 0, 1. The answer 2 would only come from adding numbers, and there are no numbers here.
- To join a number onto text in Python, convert it first: str(score).
- The empty string "" holds no characters, which makes it a perfect starting value for building text.
- msg = msg + "!" reads msg, joins the ! on the end, then stores that result back in msg.
- When a loop builds text, place separators deliberately, usually only between items, so nothing dangles at either end.
The big picture
Concatenation joins strings end to end, in the order you write them, to make one new string. Nothing is added for you: every space or comma must come from a piece, and "" adds no characters. Digits in quotation marks are text, so they join rather than add. In Python, str(score) is needed before a number joins text. msg = msg + "!" reads msg, joins the ! on the end and stores the result back in msg, which is how loops build text from "".
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
Thinking + means the same thing everywhere, or that it does your formatting. In Python, "Score: " + 7 is an error until 7 becomes str(7). Either way, every space and separator you want has to be typed in yourself.
Memory hook
Strings are strips of characters: glue them in order and you get a new strip. Nothing appears between strips unless you put it there, and mixing in numbers follows your language's rules.
Check yourself
Give the exact results of "bath" + "room", "7" + "7" and "" + "go". Then plan a loop from result = "" that outputs red, green, blue with nothing extra at either end.
Flashcards
(6)What is concatenation?
Does joining two strings put 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 27 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.