String Concatenation

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

String Concatenation

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is "Hello" + "World"?
A HelloWorld
B Hello World
2. What is "Hi " + "there"?
A Hi there
B Hithere
3. After name = "Alice", what is "Hi " + name?
A Hi name
B Hi Alice
4. What is "Good" + "bye"?
A Goodbye
B Good bye
5. What is "Hello" + " " + "World"?
A HelloWorld
B Hello World

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1'Hello' + 5 AOutput: catnap
2name = 'Ali' print('Hi' + name) BError: Missing space
3'Hello' + ' ' + 'World' CValid: Hello World
4greeting = 'Hi ' result = greeting + 'Bob' DOk: Concatenate variables
5print('cat' + 'nap') EOutput: HotDog
6a = 'Hot' b = 'Dog' print(a + b) FError: str + int not allowed

Definitions

"Hello" + "World"

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
result = "Hello" _ "World"
2.
name = "Alice" message = "Hi " _ name print(message)
3.
greeting = "Good" + _ _ + "morning"
4.
first = "Bob" last = "Smith" fullname = first + " " + ____
5.
city = "Melbourne" sentence = "I live in " + ____ print(sentence)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A first = "Hello"
B second = "World"
C result = first second
D print(result)
Question 2
A name = "Bob"
B greeting = "Hi " + Name
C print(greeting)
Question 3
A fruit = "apple"
B count = "3"
C msg = "I have " + count + fruit
D print(msg)
Question 4
A city = "Melbourne"
B country = "Australia"
C location = city + , + country
D print(location)
Question 5
A word = "Hello"
B sentence = word + " " + "World"
C print(Sentence)

Answer Key

String Concatenation
Section A: Quick Questions
Q1
A — HelloWorld
Q2
A — Hi there
Q3
B — Hi Alice
Q4
A — Goodbye
Q5
B — Hello World
Section B: Match the Pairs
Q1
'Hello' + 5 → Error: str + int not allowed
Q2
name = 'Ali' print('Hi' + name) → Error: Missing space
Q3
'Hello' + ' ' + 'World' → Valid: Hello World
Q4
greeting = 'Hi ' result = greeting + 'Bob' → Ok: Concatenate variables
Q5
print('cat' + 'nap') → Output: catnap
Q6
a = 'Hot' b = 'Dog' print(a + b) → Output: HotDog
Section C: Definitions
Q1
"Hello" + "World" — Concatenation joins strings with + but no space is added.~~"Hello" + " " + "World"
Section D: Fill in the Blanks
Q1
result = "Hello" + "World"
Q2
name = "Alice" message = "Hi " + name print(message)
Q3
greeting = "Good" + " " + "morning"
Q4
first = "Bob" last = "Smith" fullname = first + " " + last
Q5
city = "Melbourne" sentence = "I live in " + city print(sentence)
Section E: Spot the Error
Q1
C — Line 3 is missing the + operator. Use: first + second
Q2
B — Line 2 uses Name with a capital N. Python is case-sensitive. Use: name
Q3
C — Line 3 is missing a space before fruit. Use: count + " " + fruit
Q4
C — Line 3 has a comma without quotes. Use: city + ", " + country
Q5
C — Line 3 uses Sentence with a capital S. Python is case-sensitive. Use: print(sentence)