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 Spaces and punctuation marks.
Correct Answer
D Only the first and last characters of the string.
Correct Answer

Option C is the correct answer.

Detailed Explanation

The 'The len() Function' section (page 8) explicitly states: 'Crucial: It counts spaces and punctuation marks too!' The example print(len("Hello World!")) which yields 12 (10 letters + 1 space + 1 exclamation mark) further proves this.

Hint

Look for the 'Crucial' note under the len() function explanation.

Question Info