Skip to content
Advertisement

Difference between multiple if’s and elif’s?

In python, is there a difference between say:

if text == 'sometext':
    print(text)
if text == 'nottext':
    print("notanytext")

and

 if text == 'sometext':
        print(text)
 elif text == 'nottext':
        print("notanytext")

Just wondering if multiple ifs could cause any unwanted problems and if it would be better practice to use elifs.

Advertisement

Answer

Multiple if’s means your code would go and check all the if conditions, where as in case of elif, if one if condition satisfies it would not check other conditions..

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement