Question Detail

COS 102 Python strings Objective Question

Question

A student wants to join several strings and repeat a specific string multiple times. Which two operators, respectively, would they primarily use for these tasks?
Options
A <code>*</code> for joining, <code>+</code> for repeating
B <code>+</code> for joining, <code>*</code> for repeating
Correct Answer
C <code>len()</code> for joining, <code>+</code> for repeating
D <code>len()</code> for joining, <code>*</code> for repeating
Correct Answer

Option B is the correct answer.

Detailed Explanation

The 'String Operators Summary' table (page 9) shows that 'Concatenation' (joining strings) uses the + operator, and 'Repetition' (repeats a string) uses the * operator.

Hint

Recall which operator 'adds' strings together and which one 'multiplies' copies.

Question Info