Question Detail

COS 102 Python strings Objective Question

Question

Which of the following characters are counted by the len() function when determining the length of a string?
Options
A Only alphanumeric characters.
B Only letters and numbers, excluding symbols.
C All characters, including spaces, punctuation, and special characters.
Correct Answer
D All visible characters, but excluding whitespace characters.
Correct Answer

Option C is the correct answer.

Detailed Explanation

The document explicitly states, 'Crucial: It counts spaces and punctuation marks too!' The len() function counts every character that makes up the string, including letters, numbers, spaces, punctuation, and any other special characters.

Hint

The len() function considers a string as a sequence of *all* characters.

Question Info