Home → Lessons → Conditional Statements

Conditional Statements

Learn how Python makes decisions using if, elif and else statements.

Lesson 06 Beginner 15 min

What are Conditional Statements?

Conditional statements are used to make decisions in a Python program.

They execute different blocks of code depending on whether a condition is True or False.

Python uses:

if, elif and else to make decisions.

1. if Statement

The if statement executes code when a condition is True.

Example
age = 20

if age >= 18:
    print("You are an adult")
Output:
You are an adult

2. if-else Statement

The else block executes when the if condition is False.

Example
age = 16

if age >= 18:
    print("Eligible")
else:
    print("Not Eligible")
Output:
Not Eligible

3. elif Statement

The elif statement is used when we need to check multiple conditions.

Example
marks = 75

if marks >= 90:
    print("Grade A+")
elif marks >= 75:
    print("Grade A")
elif marks >= 60:
    print("Grade B")
else:
    print("Grade C")
Output:
Grade A

4. Nested if Statement

A nested if means using one if statement inside another if statement.

Example
age = 20
has_id = True

if age >= 18:
    if has_id:
        print("Entry allowed")
Output:
Entry allowed

5. Practical Example

Conditional statements can be used to check whether a number is positive, negative or zero.

Number Checking Program
number = 10

if number > 0:
    print("Positive")
elif number < 0:
    print("Negative")
else:
    print("Zero")
Output:
Positive
Important:

Python uses indentation to define the block of code inside if, elif and else.

Quick Quiz

Which keyword is used when checking another condition?

Finished this lesson?