mercredi 27 janvier 2016

Else statement for nested and unnested if

I would like to know if there is any way to have one else statement for multiple levels of if statements.

I'll elaborate:

if <condition-1>:
    if <condition-2>:
        do stuff
    elif <condition-3>:
        do other stuff
else: #if either condition-1 or all nested conditions are not met
    do some other thing

I know this could easily be solved by adding a function with the "do some other thing" and making a call to it with both a nested else and a toplevel else but I wanted to know if there was some way to make this look a little bit cleaner.

Thanks in advance, any ideas are welcome.

Aucun commentaire:

Enregistrer un commentaire