Question Detail

COS 102 Python strings Objective Question

Question

What is the purpose of the len() function when used with a string in Python?
Options
A To convert the string to a number
B To find the first character of the string
C To count the number of characters in the string
Correct Answer
D To check if the string is empty
Correct Answer

Option C is the correct answer.

Detailed Explanation

The document states, 'The len() function counts the number of characters in a string.' It also notes that it counts spaces and punctuation marks.

Hint

The name 'len' is short for 'length'.

Question Info