← 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 →- Q1. What does iter([1, 2, 3]) return?
- Q2. What does this print? (code)
- Q3. Which exception tells a for loop that an iterator has no more values?
- Q4. What does this print? (code)
- Q5. What happens when you call a generator function?
- Q6. What does this print? (code)
- Q7. Why can sum(x x for x in range(107)) use much less memory than sum([x x for x in range(107)])?
- Q8. Which two methods make a class an iterator?
- Q9. What does yield from [4, 5] do inside a generator?
- Q10. What is a key difference between return and yield?