Question Detail

COS 102 Python strings Objective Question

Question

When len("Hello World!") is executed in Python, what does the function count?
Options
A Only alphanumeric characters.
B Only letters and numbers, excluding spaces and punctuation.
C All characters, including spaces and punctuation marks.
Correct Answer
D Only words, not individual characters.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 8, under 'Measuring Text', highlights: 'Crucial: It counts spaces and punctuation marks too!'

Hint

Consider the 'Crucial' note provided about the len() function's behavior.

Question Info