Why should I use an elif instead of using if statements over and over again. I can't find any documentation on the matter. Thank you in advance.
Why should I use an elif instead of using if statements over and over again. I can't find any documentation on the matter. Thank you in advance.
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.