Bird
0
0

What does the len() function do when used on a list in Python?

easy📝 Conceptual Q11 of 15
Python - Magic Methods and Operator Overloading
What does the len() function do when used on a list in Python?
AIt returns the number of items in the list.
BIt returns the last item in the list.
CIt adds all the items in the list.
DIt removes the first item from the list.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of len()

    The len() function counts how many items are inside a collection like a list.
  2. Step 2: Apply to a list

    When used on a list, it returns the total number of elements present in that list.
  3. Final Answer:

    It returns the number of items in the list. -> Option A
  4. Quick Check:

    len(list) = number of items [OK]
Quick Trick: Remember: len() counts items, it doesn't change them. [OK]
Common Mistakes:
  • Thinking len() returns the last item
  • Confusing len() with sum()
  • Assuming len() removes items

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes