擅长:python、mysql、java
<p>当程序在函数(或函数内部的循环)中有<code>return</code>时,它将中断该函数并“返回”结果(返回关键字后面的表达式值)给调用方。返回语句之后的语句不会执行。如果return语句没有任何表达式,则返回特殊值None</p>
<p>下面的代码将帮助您更好地理解</p>
<pre><code>>>> def explain():
for i in range(10):
return(i)
>>> explain()
0
>>> def explain_():
for i in range(10):
print(i)
return "Done"
>>> explain_()
0
1
2
3
4
5
6
7
8
9
'Done'
</code></pre>