LearnFrenzy
Sign in Take a free test

List Comprehensions · List Comprehensions MCQ · Question 13

len() of a generator Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

What does len(x for x in range(5)) do?

  • A Returns 5
  • B Returns 0
  • C Raises TypeError – generators have no length Correct
  • D Returns None
Correct Answer: Option C

A generator does not know how many values it will produce. Use sum(1 for …) or build a list.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links