Skip to content

generator

Created by calling a function containing yield, or by generator expressions. One-shot iterators.

MethodReturnsMeaning
.send(value)anyResume and make value the result of the paused yield; returns the next yielded value. Non-None before the first yield raises TypeError; completion raises StopIteration
.throw(exception)anyRaise at the paused yield; returns the next value if the generator catches and yields again, else the exception propagates
.close()NoneRaise GeneratorExit at the paused yield; finally cleanup runs first. Yielding while closing raises RuntimeError
.__iter__() / .__next__()generator / anyStandard iteration; __next__ resumes with None
.__name__ / .__qualname__stringName of the creating generator function