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.
elifcan only exists if there is a relatedifstatement above itelifcan 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
# Code Format:
if boolean_condition1:
# code here
elif boolean_condition2:
# code here
elif boolean_condition3:
# code here
else:
# code hereNOTE:
if
boolean_condition1is True, it will ignore the conditional statements below itif
boolean_condition1is False, it will check the 2nd conditionif both
boolean_condition1andboolean_condition2is False, it will check the 3rd conditionif all the conditions evaluate to False, then the else’s code block will execute
Last updated