Question Detail

COS 102 Python strings Objective Question

Question

If word = "Hello", what would be the result of len(word * 2)?
Options
A 5
B 10
Correct Answer
C Error
D "HelloHello"
Correct Answer

Option B is the correct answer.

Detailed Explanation

First, word * 2 evaluates to "HelloHello". Then, len("HelloHello") counts the characters in this new string, which are 10.

Hint

Break down the expression: first the repetition, then the length calculation.

Question Info