The IF-ELIF-ELSE Statement
tags: #python/documentation/python_conditionals
What is a Multi-way Conditional Statement?
The if-elif-else statement allows you to specify multiple conditions and corresponding blocks of code to be executed based on the first true condition encountered. If none of the conditions is true, the block inside the else statement (if present) is executed.
- This allows for more than 2 branches of possibilities.
ELIFis an abbreviation ofELSE-IF- No Limit on the number of
ELIFStatements ELSEClause will indicate the end of the chain ofIFstatements, but is NOT a requirement to end a chainedIFstatement.
Basic Syntax
if condition1:
# Code to be executed if condition1 is True
elif condition2:
# Code to be executed if condition2 is True
elif condition3:
# Code to be executed if condition3 is True
# ... (additional elif blocks)
else:
# Code to be executed if all conditions are False
First True is Executed!
In a if-elif-else statement in Python, only the block associated with the first true condition is executed. Once a condition is true and its corresponding block is executed, the rest of the conditions (if any) are not evaluated.
Flow of Execution

Summary
- Each condition is checked in sequential order in which they are written.
- If one of them is
True, the corresponding block of code is executed and the statement ends. - If more than 1 condition is
True, only the firstTruecorresponding block of code is executed.