Python If Else

Learn decision making in Python using if, else and elif statements.

Python If Else

The if else statement is used to make decisions in Python programs.

If Statement

x = 10

if x > 5:
    print("x is greater than 5")
	

If Else Statement

age = 18

if age >= 18:
    print("Adult")
else:
    print("Minor")
	

Elif Statement

marks = 75

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

Nested If

x = 10

if x > 5:
    if x < 20:
        print("x is between 5 and 20")