PYTHON Tutorial



IF ELSE IN PYTHON


🔀 If Else in Python

The if-else statement in Python is used for decision-making. It allows your program to execute certain blocks of code based on specific conditions.

🔸 Basic If Statement

Executes a block of code if a condition is True.

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

🔸 If-Else Statement

Executes one block if the condition is True, another if False.

age = 16
if age >= 18:
    print("You can vote")
else:
    print("You are too young to vote")
  

🔸 If-Elif-Else Ladder

Used when you have multiple conditions to test.

marks = 85
if marks >= 90:
    print("Grade A")
elif marks >= 75:
    print("Grade B")
elif marks >= 60:
    print("Grade C")
else:
    print("Fail")
  
💡 Note: Python uses indentation (4 spaces or a tab) instead of braces to define blocks of code.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review