<div class="section" id="the-yield-statement">
<span id="yield"></span><h2>The <a class="reference internal" href="#yield"><tt class="xref std std-keyword docutils literal"><span class="pre">yield</span></tt></a> statement</h2>
<pre id="index-23">
<strong id="grammar-token-yield_stmt">yield_stmt</strong> ::=  <a class="reference internal" href="expressions.html#grammar-token-yield_expression"><tt class="xref docutils literal"><span class="pre">yield_expression</span></tt></a>
</pre>
<p>A <a class="reference internal" href="#yield"><tt class="xref std std-keyword docutils literal"><span class="pre">yield</span></tt></a> statement is semantically equivalent to a <a class="reference internal" href="expressions.html#yieldexpr"><em>yield
expression</em></a>. The yield statement can be used to omit the parentheses
that would otherwise be required in the equivalent yield expression
statement. For example, the yield statements</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="k">yield</span> <span class="o">&lt;</span><span class="n">expr</span><span class="o">&gt;</span>
<span class="k">yield from</span> <span class="o">&lt;</span><span class="n">expr</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>are equivalent to the yield expression statements</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="p">(</span><span class="k">yield</span> <span class="o">&lt;</span><span class="n">expr</span><span class="o">&gt;</span><span class="p">)</span>
<span class="p">(</span><span class="k">yield from</span> <span class="o">&lt;</span><span class="n">expr</span><span class="o">&gt;</span><span class="p">)</span>
</pre></div>
</div>
<p>Yield expressions and statements are only used when defining a <a class="reference internal" href="../glossary.html#term-generator"><em class="xref std std-term">generator</em></a>
function, and are only used in the body of the generator function.  Using yield
in a function definition is sufficient to cause that definition to create a
generator function instead of a normal function.</p>
<p>For full details of <a class="reference internal" href="#yield"><tt class="xref std std-keyword docutils literal"><span class="pre">yield</span></tt></a> semantics, refer to the
<a class="reference internal" href="expressions.html#yieldexpr"><em>Yield expressions</em></a> section.</p>
</div>
