LearnFrenzy
Sign in Take a free test

Iterators and Generators · Iterators and Generators MCQ · Question 7

Why generators save memory Answer, explanation & discussion

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

Why does a generator over a billion numbers use very little memory?

  • A It produces one value at a time when asked instead of storing them all Correct
  • B It compresses the numbers
  • C It stores the numbers on disk
  • D Python limits generators to 1000 values
Correct Answer: Option A

Only the generator's current state (its local variables) is kept.

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