Content deleted Content added
Pi Delport (talk | contribs) attempt to tighten the Python generator description |
Pi Delport (talk | contribs) clearer statement of generators' use |
||
Line 23:
In Python, a generator can be thought of as an iterator that contains a frozen [[stack frame]]. Whenever the iterator's <code>next()</code> method is called, 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.
Because generators compute their yielded values only on demand, they are useful for representing sequences that are expensive to compute, or even infinite.
==References==
|