Skills101
← All practice quizzes

Quiz: Iterators and Generators

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

What really happens inside a for loop. Iterables and iterators, writing your own iterator, generator functions with yield, generator expressions and why they save memory.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does iter([1, 2, 3]) return?

  2. Question 2

    What does this print?

    it = iter("ab")
    next(it)
    print(next(it))
    
  3. Question 3

    Which exception tells a for loop that an iterator has no more values?

  4. Question 4

    What does this print?

    def gen():
        yield 1
        yield 2
    g = gen()
    print(list(g), list(g))
    
  5. Question 5

    What happens when you call a generator function?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →