擅长:python、mysql、java
<p>没有。当我写<a href="http://legacy.python.org/dev/peps/pep-0255/" rel="noreferrer">"Simple Generators PEP"</a>时,我注意到:</p>
<blockquote>
<pre><code>Q. Then why not allow an expression on "return" too?
A. Perhaps we will someday. In Icon, "return expr" means both "I'm
done", and "but I have one final useful value to return too, and
this is it". At the start, and in the absence of compelling uses
for "return expr", it's simply cleaner to use "yield" exclusively
for delivering values.
</code></pre>
</blockquote>
<p>但这一点一直没有得到重视。在完成之前;-),您可以将生成器的第一部分编写为:</p>
<pre><code>if n == 0:
yield ""
return
</code></pre>
<p>然后可以删除<code>else:</code>语句并删除其余语句。在</p>