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 + last
4 full = first + " " + last
5 msg = "Hello, " + full
6 msg = msg + "!"
7 print(msg)
firstlastfullmsg
"Ada"

Output

 

Step 1: first now holds the string Ada. A string is just a sequence of characters, here A, d and a.

1 / 7

Use Next to run one line at a time, and check your prediction for line 3 before you look.

Step 1 of 7: first now holds the string Ada. A string is just a sequence of characters, here A, d and a..

Watch out: The quotation marks aren't part of the text. They only mark where a string starts and ends, which is also what lets you see where a space is. When the message is printed, the quotation marks don't appear.

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?

Computer Science · Programming

Spot the line that gets the order wrong

A class register should show each student as surname, comma, first name, then their house in brackets. For Ada Lovelace in Babbage house it should print exactly: Lovelace, Ada (Babbage). Which line makes it go wrong?

A student's program — which line goes wrong?

Your turn

Write it, then mark it

A program already stores a town in the variable town and a day in the variable day, for example town = "Leeds" and day = "Friday". Write code that uses concatenation to store a message in the variable message and then outputs it. With the example values, the output must be exactly: Leeds market is open on Friday Your code must still work if town and day hold different values. [3 marks]

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

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

1Concatenation is joining strings end to end to make a new string.
2In Python and many other languages, + joins values that are strings and adds values that are numbers.
3Nothing is inserted between the pieces. Every space in the result must be joined in: as a " " string, or inside a literal.
4The order you write the pieces is the order they appear: a + b and b + a give different strings.
5Digits inside quotation marks are text, so "12" + "30" is "1230".
6Literals and string variables can be mixed freely, and msg = msg + "!" joins onto the current value and stores the longer string back in msg.

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?
Joining two or more strings end to end to make one new string.
Does joining two strings add a space between them?
No. The characters are copied exactly, so "sun" + "set" gives "sunset". Any space must be joined in yourself.
Two ways to get a space between first and last when you join them
Join a space string, first + " " + last, or put the space inside a literal, such as "Hello, " + first.
What is "4" + "4" when both are strings?
"44". Digits in quotation marks are text, so they are joined, not added.
Does the order of the pieces matter in a join?
Yes. The result keeps the order written: "top" + "hat" is "tophat", but "hat" + "top" is "hattop".
What does name = name + "!" do?
Takes the current value of name, joins ! onto the end, and stores the longer string back in 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 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.