Question Detail

COS 102 Python strings Objective Question

Question

What will be the output of print("Go!" * 2)?
Options
A "Go! 2"
B "Go!Go!"
Correct Answer
C "Go! Go!"
D An error, as a string cannot be multiplied by an integer.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The repetition operator '*' repeats the string the specified number of times and joins them together. "Go!" repeated twice is "Go!Go!". This is also confirmed in the 'Predict the Output!' section (page 11).

Hint

The repetition operator joins the copies without adding spaces by default.

Question Info