擅长:python、mysql、java
<p>从<a href="https://docs.python.org/3/tutorial/errors.html" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>A finally clause is <strong>always</strong> executed before leaving the try statement.</p>
</blockquote>
<p><sup>@deceze在他的<a href="https://stackoverflow.com/a/38094980/1735406">answer</a>中引用了更相关的部分</p>
<p>函数返回<code>finally</code>子句中的字符串,并且在返回后不会引发异常,这就是打印的内容。你知道吗</p>
<p>如果您尝试执行:</p>
<pre><code>>>> try:
... raise Exception
... finally:
... print('yes')
...
yes
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
Exception
</code></pre>
<p>然后,如您所见,“yes”被打印出来,异常被抛出到print语句之后。你知道吗</p>