Python nested if else

In this article, we will see definition of Python nested if else statement and examples.

In general nested if-else statement is used when we want to check more than one condition. Conditions are executed from top to bottom and checks each condition whether it evaluates to true or not. If a condition is found then statements block associated with the condition executes otherwise it goes to next condition.

Python nested if else Syntax:

if expression: if expression: statements else: statements else: statements

Examples:

1. Find the year is leap or not using Python nested if statement:

year=int(input("Enter the valid 4 digit year: ")) if year%4==0: if year%100==0: if year%400==0 print("Yes it is leap year") else: print("Not leap year") else: print("Yes it is leap year") else: print("Not leap year")