Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Python evaluate multiple conditions in or statement?

Tags:

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]]