if–elif–else Statement

The if elif else statement is a conditional statement used to check multiple conditions and execute one matching block of code.

The term elif means “else if”, and it helps to check conditions one by one.

When the program runs, it executes the first True condition and skips the remaining ones.

What is If Elif Else Statement?

The if elif else statement is used to check multiple conditions one after another.

Python executes the block whose condition becomes True.

If none of the conditions become True, the else block executes.

Meaning of elif

The word:

elif

means:

Else If

It is used to add extra conditions after the if statement.

If Elif Else Statement in Python

The if elif else statement is one of the most powerful decision-making statements in Python programming.
It is used when a program has more than two choices or conditions.

In real life, many situations require checking multiple conditions.

For example:

  • Marks above 90 → Excellent
  • Marks above 75 → Very Good
  • Marks above 35 → Pass
  • Otherwise → Fail

Python provides the if elif else statement to handle these kinds of multiple conditions efficiently.

Why If Elif Else Statements are Important

If elif else statements are important because they help programs:

  • make multiple decisions
  • handle complex conditions
  • improve program logic
  • create intelligent applications
  • build real-world systems

Without if elif else statements, checking multiple conditions would become difficult and repetitive.

Explanation 

  • The program starts with if
  • If the condition is False, it checks the elif condition
  • It keeps checking conditions one by one
  • Stops when it finds a True condition
  • If none are True, the else block runs
  • In the end, only one block executes

Real-Time Examples of If Elif Else

Condition Output
Marks >= 90 Excellent
Marks >= 75 Very Good
Marks >= 35 Pass
Otherwise Fail

Explanation of the If-Elif-Else Flowchart in Python

The given diagram explains how the if-elif-else statement works in Python programming.
It shows the flow of execution when a program checks multiple conditions one by one.

This flowchart helps beginners understand:

  • how Python checks conditions
  • which block gets executed
  • how decision making works in Python

If the Condition is True

If the condition becomes True:

  • Python executes the if code block
  • Remaining elif and else blocks are skipped

If the Condition is False

If the condition becomes False:

  • Python does not execute the if block
  • It moves to the next condition (elif)

If elif Condition is False

If the elif condition is also False:

  • Python moves to the else block

If elif Condition is True

If the elif condition becomes True:

  • Python executes the elif code block
  • Remaining conditions are skipped

End of the If-Elif-Else Statement

After executing one block:

  • Python exits the conditional structure
  • Program continues with the next statements

Syntax

if condition1:
    statements

elif condition2:
    statements

elif condition3:
    statements

else:
    statements

Explanation of Syntax

Part Purpose
if Checks the first condition
elif Checks additional conditions
else Executes when all conditions are False
: Colon symbol required
Indentation Defines the block of code

Example 1

marks = 75

if marks >= 90:
    print("A Grade")
elif marks >= 75:
    print("B Grade")
elif marks >= 50:
    print("C Grade")
else:
    print("Fail")

Output:

B Grade

Example 2

time = 14

if time < 12:
    print("Morning")
elif time < 18:
    print("Afternoon")
else:
    print("Evening")

Output:

Afternoon

How If Elif Else Works

The flow of execution is:

  1. Python first checks the if condition
  2. If True → executes that block
  3. If False → checks the next elif
  4. Continues checking until a True condition is found
  5. If all conditions are False → executes the else block

Common Beginner Mistakes

Mistake Problem
Forgetting colon : Syntax error
Wrong indentation Indentation error
Using = instead of == Logical error
Incorrect condition order Wrong output


➤ Summary

  • The if elif else statement in Python is used when a program needs to check multiple conditions.

    Important points:

    • if checks the first condition
    • elif checks additional conditions
    • else executes when all conditions are False
    • only one block executes

    The if elif else statement is widely used in real-world applications such as grading systems, banking software, gaming applications, age categorization systems, and online platforms.

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What does elif mean?

elif means else if.

Question 2

How many blocks run in if–elif–else?

Only the first True condition block executes.

Question 3

What is the output?

marks = 40

if marks >= 90:
    print("A")
elif marks >= 50:
    print("B")
else:
    print("Fail")

40 does not satisfy conditions → else runs.

Question 4

What is the output?

x = 15

if x > 20:
    print("A")
elif x > 10:
    print("B")
else:
    print("C")

First is False, second is True → prints B.

Question 5

What is the output?

x = 25

if x > 10:
    print("A")
elif x > 20:
    print("B")
else:
    print("C")

First condition is True, so it stops and prints A.

Congratulations!

You've successfully mastered the knowledge check for "if–elif–else Statement."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic if–else Statement Next Topic Nested if Statements