← Quiz: Iterators and Generators: all 10 questions
Quiz: Iterators and Generators · Question 4 of 10
What does this print? (code)
What does this print?
def gen():
yield 1
yield 2
g = gen()
print(list(g), list(g))
- A.[1, 2] [1, 2]
- B.[1, 2] []
- C.[] []
- D.An error
Answer & explanation
Correct answer: [1, 2] []
A generator is used up after one full pass.
Can you get the rest right without peeking?
Take the timed Quiz: Iterators and Generators quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →