What does the second next call return?
values = (x for x in range(1, 4))
next(values)
print(next(values))Answer & explanation
Answer: 2
Each next resumes the generator and yields the next item in its range.
Practice iterators & generators with self-contained questions. Check your answer, then use the explanation to understand the reasoning.
values = (x for x in range(1, 4))
next(values)
print(next(values))Answer: 2
Each next resumes the generator and yields the next item in its range.