0
0
Pythonprogramming~5 mins

String concatenation and repetition in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is string concatenation?
String concatenation is joining two or more strings together to make one longer string.
Click to reveal answer
beginner
How do you concatenate strings in Python?
Use the + operator to join strings. For example, 'Hello' + ' ' + 'World' results in 'Hello World'.
Click to reveal answer
beginner
What does string repetition mean?
String repetition means repeating the same string multiple times in a row.
Click to reveal answer
beginner
How do you repeat a string in Python?
Use the * operator with an integer. For example, 'ha' * 3 results in 'hahaha'.
Click to reveal answer
intermediate
What is the output of this code: 'Hi' + '!' * 3?
The output is 'Hi!!!' because '!' is repeated 3 times and then concatenated with 'Hi'.
Click to reveal answer
Which operator is used to join two strings in Python?
A/
B*
C-
D+
What does 'abc' * 2 produce?
A'abcabc'
B'abc2'
C'abc abc'
D'aabbcc'
What is the result of 'Hello' + ' ' + 'World'?
A'HelloWorld'
B'Hello World'
C'Hello World'
D'Hello+World'
Which of these is NOT a valid way to concatenate strings in Python?
A'a' + 'b'
B'a' * 3
C'a' - 'b'
D'a'.join(['b', 'c'])
What will '!' * 0 return?
A'' (empty string)
B'!'
CError
D'0'
Explain how to join two strings and repeat a string in Python with examples.
Think about using + to add strings and * to repeat them.
You got /4 concepts.
    What happens if you multiply a string by zero or a negative number in Python?
    Consider how repetition count affects the output.
    You got /3 concepts.