The if-elif-else Statement
This lesson highlights the main properties of the `if-elif-else` statement.
We'll cover the following
The if-else
statement handles two sides of the same condition: True
and False
. This works very well if we’re working with a problem that only has two outcomes.
However, in programming, it isn’t always a True
or False
scenario, and a problem can have multiple outcomes.
This is where the if-elif-else
statement shines. It is the most comprehensive conditional statement because it allows us to create multiple conditions easily.
The elif
stands for else if, indicating that if the previous condition fails, try this one.
Structure #
The if
and else
blocks will remain the same. The elif
statement comes in between the two.