Python·100 questions

What are generators?

Answer
Function with yield.
Returns an iterator.
Lazy evaluation (saves memory).
next(gen) — get next element.
Generator expression: (x*2 for x in range(10)).
Was this answer helpful?

More questions in this topic

Related questions from other topics