Occasionally, I have this problem where I want to check:
a = 'my string'
if 'string1' in a or 'string2' in a or 'string3' in a ... or 'stringN' in a:
[[do something]]
else:
[[something else]]
Suppose I know that there's a 90% chance 'string1' in a
evaluates to True
. Will Python still evaluate if 'string2' in a
in this case where 'string1' in a
is True
? Or is it technically more efficient to write:
if 'string1' in a:
[[do something]]
elif 'string2' in a:
[[do something]]
elif 'string3' in a:
[[do something]]
...
elif 'stringN' in a:
[[do something]]
else:
[[something else]]
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