Is there a way in python to have an if statement, that will execute if the condition is met or an error occurs in testing it, but not if it just tests false.
(Fictional) Example:
ErrIf 12/x % 2 ==0:
Print('Yes')
Expected behavior:
x=3 -> Yes
x=4 ->
x=0 -> Yes
I know I can do the following:
try:
if condition:
do stuff
except:
do same stuff
but this violates the DRY principle so I'm wondering if there's a simpler way.
Aucun commentaire:
Enregistrer un commentaire