Question Detail

COS 102 Python strings Objective Question

Question

What is the result of len("Python 3")?
Options
A 7
B 8
Correct Answer
C 6
D An error because of the space.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The len() function counts all characters, including spaces. 'Python' has 6 characters, '3' has 1 character, and there's 1 space between them. So, 6 + 1 + 1 = 8. This is also confirmed in the 'Predict the Output!' section (page 11).

Hint

Don't forget to count spaces when using len().

Question Info