Content deleted Content added
AdaHephais (talk | contribs) Internal link Tags: Visual edit Mobile edit Mobile web edit |
Funkywizard (talk | contribs) Tags: Reverted Mobile edit Mobile web edit |
||
Line 501:
</syntaxhighlight>
In Python, a generator can be thought of as an [[iterator]] that contains a frozen [[stack frame]]. Whenever <code>next()</code> is called on the iterator, Python resumes the frozen frame, which executes normally until the next <code>yield</code> statement is reached. The generator's frame is then frozen again, and the yielded value is returned to the caller. This can be far more memory efficient when iterating over large datasets<ref>IOFLOOD Python Generators[https://ioflood.com/blog/python-generator/#The_Power_of_the_yield_Keyword]</ref>.
PEP 380 (implemented in Python 3.3) adds the <code>yield from</code> expression, allowing a generator to delegate part of its operations to another generator or iterable.<ref name="pep380">[https://www.python.org/dev/peps/pep-0380/ PEP 380 -- Syntax for Delegating to a Subgenerator]</ref>
|