Bird
0
0

What does the len() function return when used on a string in Python?

easy📝 Conceptual Q1 of 15
Python - Magic Methods and Operator Overloading
What does the len() function return when used on a string in Python?
AThe number of words in the string
BThe number of characters in the string
CThe first character of the string
DThe last character of the string
Step-by-Step Solution
Solution:
  1. Step 1: Understand what len() does for strings

    The len() function counts how many characters are in the string, including spaces and punctuation.
  2. Step 2: Apply len() to a string

    For example, len('hello') returns 5 because there are 5 characters.
  3. Final Answer:

    The number of characters in the string -> Option B
  4. Quick Check:

    Length of string = number of characters [OK]
Quick Trick: len() counts characters in strings, not words [OK]
Common Mistakes:
  • Thinking len() counts words
  • Confusing len() with string indexing
  • Assuming len() returns last character
  • Using len() to get first character

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes