🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Iterators and Generators: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does iter([1, 2, 3]) return?
  2. Q2. What does this print? (code)
  3. Q3. Which exception tells a for loop that an iterator has no more values?
  4. Q4. What does this print? (code)
  5. Q5. What happens when you call a generator function?
  6. Q6. What does this print? (code)
  7. Q7. Why can sum(x x for x in range(107)) use much less memory than sum([x x for x in range(107)])?
  8. Q8. Which two methods make a class an iterator?
  9. Q9. What does yield from [4, 5] do inside a generator?
  10. Q10. What is a key difference between return and yield?