3 Python Else Statement

1. What is an Else Statement?

The else statement is used with if.

In simple words:
👉 Python checks the if condition
👉 If the condition is True, Python runs if code
👉 If the condition is False, Python runs else code

2. Simple If–Else Example

Example


 

3. When Does Else Run?

else runs only when the if condition is false.

Example


 

4. Else with Comparison Operators

Example


 

5. Else with String Check

Example


 

6. Else with Boolean Values

Example


 

7. Else Must Come After If or Elif

❌ Wrong


 

✔ Correct


 

8. Important Rule: Indentation

Python uses indentation (spaces) to understand code blocks.

❌ Wrong


 

✔ Correct


 

9. Common Beginner Mistakes

❌ Using else Without if


 

❌ Error.

❌ Forgetting Colon :

10. Simple Practice Examples

Example 1: Check Temperature


 

Example 2: Check Login


 

Example 3: Check Zero


 

11. Summary (Python Else Statement)

✔ Runs when if condition is false
✔ Must come after if
✔ Uses indentation
✔ Handles alternative condition
✔ Very important in decision making

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • If–Elif–Else Statement

  • Nested If–Else

  • If–Else Exercises

  • Real-life Examples

Just tell me 😊

You may also like...