Question Detail

COS 102 Python strings Objective Question

Question

What will be the output of the following Python code?
text = "Python! "
print(text * 2)
Options
A <code>Python!Python!</code>
B <code>Python! Python! </code>
Correct Answer
C <code>Python! Python!</code>
D <code>Python!Python! </code>
Correct Answer

Option B is the correct answer.

Detailed Explanation

The string 'Python! ' includes a trailing space. When repeated twice using the * operator, this space is also repeated, resulting in 'Python! Python! '.

Hint

Pay close attention to all characters in the string, including any leading or trailing spaces, as they will be repeated.

Question Info