Multiple Decisions
By combining if
and else
we were able to create binary pathways. With another built-in conditional keyword, we can create multiple pathways in our code.
elif
statement
elif
statementelif
is a built-in keyword related to if statements.
elif
can only exists if there is a relatedif
statement above itelif
can have its own condition, and it will execute its code block if the Boolean condition is TrueAfter the first if statement, you are allowed to have as many elif statements as youโd like
It is recommended that your elifโs boolean condition is related to the condition that comes before it
NOTE:
if
boolean_condition1
is True, it will ignore the conditional statements below itif
boolean_condition1
is False, it will check the 2nd conditionif both
boolean_condition1
andboolean_condition2
is False, it will check the 3rd conditionif all the conditions evaluate to False, then the elseโs code block will execute
Last updated