Question Detail

COS 102 Python strings Objective Question

Question

What is the purpose of the len() function when working with strings?
Options
A To convert a string to a list of characters.
B To find the first occurrence of a specific character in a string.
C To count the number of characters in a string.
Correct Answer
D To check if a string contains only letters.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 8, 'The len() Function', clearly states, 'The len() function counts the number of characters in a string.'

Hint

The name of the function itself provides a strong clue about its purpose.

Question Info