Question Detail

COS 102 Python strings Objective Question

Question

Consider the following Python code:
item = 'book'
count = 3
message = item * count
What will be the value of message?
Options
A <code>'bookbookbook'</code>
Correct Answer
B <code>'book book book'</code>
C <code>'book' * 3</code>
D <code>'book3'</code>
Correct Answer

Option A is the correct answer.

Detailed Explanation

The * operator performs string repetition. 'book' repeated 3 times results in 'bookbookbook'.

Hint

The repetition operator simply duplicates the string as many times as specified by the integer.

Question Info