<div dir="ltr"><dt id="term-generator" style="font-weight:bold;font-size:1.1em;font-family:"Lucida Grande",Arial,sans-serif">generator</dt><dd style="margin-top:3px;margin-bottom:10px;margin-left:30px;text-align:justify;line-height:20.8px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px"><p class="" style="line-height:22.4px;margin-top:0px!important">A function which returns a <a class="" href="https://docs.python.org/3.6/glossary.html#term-generator-iterator" style="color:rgb(99,99,187);text-decoration:none">generator iterator</a>. It looks like a normal function except that it contains <a class="" href="https://docs.python.org/3.6/reference/simple_stmts.html#yield" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">yield</span></code></a> expressions for producing a series of values usable in a for-loop or that can be retrieved one at a time with the <a class="" href="https://docs.python.org/3.6/library/functions.html#next" title="next" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">next()</span></code></a> function.</p><p class="" style="margin-top:0px;line-height:22.4px">Usually refers to a generator function, but may refer to a <em>generator iterator</em> in some contexts. In cases where the intended meaning isn’t clear, using the full terms avoids ambiguity.</p></dd><dt id="term-generator-iterator" style="font-weight:bold;font-size:1.1em;font-family:"Lucida Grande",Arial,sans-serif">generator iterator</dt><dd style="margin-top:3px;margin-bottom:10px;margin-left:30px;text-align:justify;line-height:20.8px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px"><p class="" style="line-height:22.4px;margin-top:0px!important">An object created by a <a class="" href="https://docs.python.org/3.6/glossary.html#term-generator" style="color:rgb(99,99,187);text-decoration:none">generator</a> function.</p><p class="" style="margin-top:0px;line-height:22.4px">Each <a class="" href="https://docs.python.org/3.6/reference/simple_stmts.html#yield" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">yield</span></code></a> temporarily suspends processing, remembering the location execution state (including local variables and pending try-statements). When the <em>generator iterator</em> resumes, it picks-up where it left-off (in contrast to functions which start fresh on every invocation).</p></dd><dt id="term-generator-expression" style="font-weight:bold;font-size:1.1em;font-family:"Lucida Grande",Arial,sans-serif">generator expression</dt><dd style="margin-top:3px;margin-bottom:10px;margin-left:30px;text-align:justify;line-height:20.8px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px"><p class="" style="line-height:22.4px;margin-top:0px!important">An expression that returns an iterator. It looks like a normal expression followed by a <a class="" href="https://docs.python.org/3.6/reference/compound_stmts.html#for" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">for</span></code></a> expression defining a loop variable, range, and an optional <a class="" href="https://docs.python.org/3.6/reference/compound_stmts.html#if" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">if</span></code></a> expression. The combined expression generates values for an enclosing function:</p><div class="" style=""><div class="" style="background:rgb(238,255,204)"><span class="" title="Hide the prompts and output" style="border:1px solid rgb(170,204,153);color:rgb(170,204,153);font-family:monospace;padding-left:0.2em;padding-right:0.2em;border-radius:0px 3px 0px 0px">>>></span><pre style="padding:5px;color:rgb(51,51,51);line-height:18.528px;border:1px solid rgb(170,204,153);font-family:monospace,sans-serif;font-size:15.44px;border-radius:3px"><span class="" style="color:rgb(198,93,9);font-weight:bold">>>> </span><span class="" style="color:rgb(0,112,32)">sum</span><span class="">(</span><span class="">i</span><span class="" style="color:rgb(102,102,102)">*</span><span class="">i</span> <span class="" style="color:rgb(0,112,32);font-weight:bold">for</span> <span class="">i</span> <span class="" style="color:rgb(0,112,32);font-weight:bold">in</span> <span class="" style="color:rgb(0,112,32)">range</span><span class="">(</span><span class="" style="color:rgb(32,128,80)">10</span><span class="">))</span> <span class="" style="color:rgb(64,128,144);font-style:italic"># sum of squares 0, 1, 4, ... 81</span>
<span class="" style="color:rgb(51,51,51)">285</span></pre></div></div></dd></div>