 <p>The <code>finally</code> part is <em>always</em> executed before leaving the <code>try</code> block. <code>return 0</code> would leave the <code>try</code> block. So the <code>finally</code> part is executed first and returns 1.</p> <p><a href="https://docs.python.org/2/tutorial/errors.html#predefined-clean-up-actions" rel="nofollow">Documentation</a></p>