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

Output

 

Step 1: first holds the string Ada. A string is just a row of characters: A, d, a.

1 / 7

+ copies characters. It doesn't think about what would look nice.

Step 1 of 7: first holds the string Ada. A string is just a row of characters: A, d, a..

Watch out: Before you step onto full = first + last, decide exactly what full will hold. Most people get this one wrong the first time.

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?

Find the line that scrambles the register

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

A student's program — which line goes wrong?

Your turn: write the join

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 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

1Concatenation joins strings end to end in the written order and produces a string. It is not numeric addition.
2In Python, + joins two strings, and a number must be converted with str() before it can be joined onto text.
3No separator is added automatically. Include each space, comma, full stop or newline you need, exactly once.
4The empty string "" contains no characters. Joining it changes nothing you can see, which is why it makes a good starting accumulator.
5Concatenation is order-sensitive: a + b is usually different from b + a.
6An assignment such as msg = msg + "!" reads msg, joins the ! on the end and stores the result back in msg.
7A loop can build text piece by piece. Decide whether each separator goes before, after or between items, so there's no stray space or comma at the ends.

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?
Joining strings end to end, in order, to form one new string. An empty string can be one of the pieces; it adds no characters.
Does joining two strings put a space between them?
No. The result has exactly the characters of the pieces, so "sun" + "set" gives "sunset". Add a space, comma or newline yourself when you need one.
Two ways to get a space between first and last when you join them
Join a one-space string, first + " " + last, or put the space inside a literal, such as "Hello, " + first. Count the spaces exactly.
What is "4" + "4" when both are strings?
"44". To add them as numbers, convert them to numbers first; to join a number onto text in Python, convert the number to a string first.
Does the order of the pieces matter in a join?
Yes. Concatenation is not commutative: "top" + "hat" is "tophat", but "hat" + "top" is "hattop". Separators stay exactly where you wrote them.
What does name = name + "!" do?
Reads the current value, joins ! onto the end, then stores that result back in name. In a loop the same move builds up text, often starting from "".

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 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.