DEV Community

Sameer Qaiser
Sameer Qaiser

Posted on

If-Else Statements: When I Finally Got It

📌 Quick Info

  • Topic: If-Else Statements in Python
  • Target Audience: Upper beginners who know basic Python
  • Goal: Help someone understand if-else in 5 minutes

1. Introduction

"When I first started learning Python, I didn't understand why I needed if-else. I just wrote code that ran line by line. Then I wanted to build a program that made decisions — like checking if someone was old enough to vote. That's when I discovered if-else, and everything clicked."


2. The Problem (Without If-Else)

Imagine you want to check if someone can vote:

age=18
How do I check if they're old enough?
Without if-else, my code can't make this decision
💬 ชาวเน็ตแห่แชร์: sameerqaiser/if else statements when i finally got it fd - Kapook Update 2025 💬 ชาวเน็ตแห่แชร์: sameerqaiser/if else statements when i finally got it fd - Kapook Update 2025
age = 18

if age >= 18:
    print("You can vote!")
else:
    print("Too young to vote")
💬 ชาวเน็ตแห่แชร์: sameerqaiser/if else statements when i finally got it fd - Kapook Update 2025 💬 ชาวเน็ตแห่แชร์: sameerqaiser/if else statements when i finally got it fd - Kapook Update 2025

Output:
You can vote!

5. What I Learned

  • If-else lets my code make decisions
  • The condition must be TRUE for the if block to run
  • The else block runs when the condition is FALSE
  • I can use comparison operators: >=, <, <=, ==, !=, >, <

6. Conclusion

If-else seemed confusing at first. But once I practiced with simple examples like voting and marks, it became my favorite tool for building interactive programs.

Top comments (1)

💬 ชาวเน็ตแห่แชร์: sameerqaiser/if else statements when i finally got it fd - Kapook Update 2025
 
mk023 profile image
Marco •

I liked how simple and focused this is.

If-else is one of those concepts that looks almost trivial once you understand it, but before that first “click” it can feel strangely abstract. Framing it as the moment code stops simply running line by line and starts making decisions is a really clear way to explain it.

The voting example works well because the condition and the outcome are immediately understandable, which makes the concept easier to remember.

Congratulations on making it into the Hall of Fame, very well deserved. 🎉 And if you ever feel like stopping by my corner of DEV, you're always welcome. I'm also open to collaborations, so feel free to reach out if something around my work ever feels relevant.