- Published on
Elif
- Authors
- Name
- Jason Deramo
Some decisions in life aren’t simple Yes/No answers (i.e., boolean). Often, we need additional pieces of information to help us navigate the way beyond and through. When we logically think of coding problems, similar scenarios are presented.

AI-Generated (ChatGPT©)
In Python, the elif
keyword is used in conditional statements, which allow your programs to execute certain code based on the evaluation of conditions. The elif
stands for "else if," and it provides a way to check multiple expressions for truth and executes a code block once the conditions are met.
if-elif-else
Basic Structure of if condition1:
# code block 1
elif condition2:
# code block 2
else:
# code block 3
if condition1
- This checks ifcondition1
isTrue
. If it is, the program executes code block 1.elif condition2
- Ifcondition1
is notTrue
, the program checkscondition2
. Ifcondition2
isTrue
, it executes code block 2.else
(optional) - If neithercondition1
norcondition2
isTrue
, the program defaults to executing code block 3.
When considering the many possible decisions and outcomes you face, know there are often multiple conditions at play. Perhaps you’re struggling with an issue, or trying to understand your purpose in life. Just make the next best choice and leave the rest to God. Give yourself an if
(or elif
) and make sure to check your syntax.