Is it possible to write an else
at the end of an if
-row which only gets executed if none of all the if
statements are true? Example:
if foo==5:
pass
if bar==5:
pass
if foobar==5:
pass
else:
pass
In this example, the else part gets executed if foobar
isn't 5, but I want it to be executed if foo
, bar
and foobar
aren't 5. (But, if all statements are true, all of them have to be executed.)
How about doing something like this? Making four if statements but the fourth if statement won't be run if one of the other three is run because the other statements change the variable key
key = True
if foo == 5:
key = False
if bar == 5:
key = False
if foobar == 5:
key = False
if key:
pass # this would then be your else statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With