else
is the catch-all after all the if
and elif
statements were false. Putting it in the middle would be a syntax error.
Don't think of the else
"checking the conditions." Think of it as the control flow never even reaches the else
if the others were true. The same is true for multiple elif
.
Consider this:
if False:
print 'first'
elif True:
print 'second'
elif True:
print 'third'
Even third
won't print, because the second one was true. It doesn't matter that the third was true, because it's not even evaluated.
This can have some side effects too, if you're calling functions:
if send_email(to_coworker):
pass
elif send_email(to_boss):
pass
Assuming the function returns True
if it succeeds, the email to your boss will only send if the email to your coworker fails, even though the function would need to be called to evaluate the elif condition