擅长:python、mysql、java
<p>在您的<code>print</code>之前有三个<code>return</code>,其中一个在<code>else</code>语句中,这意味着至少要执行其中一个,因此您的<code>print</code>甚至不能被执行,您应该将它移到函数定义之后以查看某些内容:</p>
<pre><code>def collatz(n):
print(i) # <= print here
if n==1:
....
</code></pre>
<p>查看有关<a href="https://docs.python.org/3/reference/simple_stmts.html#return" rel="nofollow noreferrer">^{<cd5>}</a>的更多信息。片段:</p>
<blockquote>
<p><a href="https://docs.python.org/3/reference/simple_stmts.html#return" rel="nofollow noreferrer"><code>return</code></a> leaves the current function call with the expression list (or <code>None</code>) as return value.</p>
</blockquote>