Why elif statement instead of if statement? [duplicate]

You use if, elif and else if you want one and only one of the cases to execute. In other words, the cases are mutually exclusive.

It also allows for short-circuiting logic. Upon find the first if of elif that is True, you can skip checking the conditions for all following cases. If you simply had a series of if statements, you’d have to check all of their conditions no matter what.

Browse More Popular Posts

Leave a Comment