Reputation:
Does the order of multiple "elif" statements matter in python, specifically in string checking
for example:
if 'foo' in line:
#do something
elif 'bar' in line:
#do other thing
elif 'coffe' in line:
#do other other thing
...
else:
#something something
Upvotes: 0
Views: 970
Reputation: 4472
Yes, the if-else statements are executing sequentially which means that python will run the if statement and if it is false then it will run the next elif and so on until the else statement that is executing only if all the above are false.
Upvotes: 1