🐍 Python If Else Statements for Beginners

📚 Table of Contents

  • What are Conditional Statements?
  • if Statement
  • if else Statement
  • if elif else Statement
  • Comparison Operators
  • Logical Operators
  • Nested If Statement
  • Practice Examples
  • FAQ

💡 Quick Tip

Use conditional statements to make your programs take decisions.

⚠️ Common Mistakes

  • Forgetting colon (:) after condition.
  • Wrong indentation.
  • Using = instead of ==.

✍️ By Roshni Code Charm

📅 July 2026 | ⏱️ 6 min read

🤔 What are Conditional Statements?

Conditional statements are used to make decisions in Python. They execute different code based on conditions.

✅ if Statement

The if statement runs code only when a condition is true.


age = 18

if age >= 18:
    print("You can vote")

🔄 if else Statement

The else block runs when the if condition is false.


age = 16

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

🔀 if elif else Statement

elif is used when we have multiple conditions.


marks = 85

if marks >= 90:
    print("Grade A+")

elif marks >= 75:
    print("Grade A")

else:
    print("Need Improvement")

⚖️ Comparison Operators

🔗 Logical Operators

📌 Nested If Statement

An if statement inside another if statement is called nested if.


age = 20

if age >= 18:

    if age <= 60:
        print("Eligible")

🚀 Practice Examples

❓ Frequently Asked Questions

1. Why do we use if else in Python?

if else helps programs make decisions.

2. What is elif?

elif is used to check multiple conditions.

3. Is indentation important in Python?

Yes, Python uses indentation to define code blocks.