if–else Statement
An if–else statement is used to check a condition with two possible outcomes.
- If the condition is
True→ one block runs - If the condition is
False→ another block runs
It uses the keywords if and else
Explanation
First, the program checks the condition.
- If True → executes if block
- If False → executes else block
✔ Only one block will run
It is useful for yes/no decisions.

Real-Time Scenarios
- If you study → pass, else → fail
- If switch is ON → light glows, else → OFF
- If ticket is available → travel, else → stay
- If number is even → do one task, else → another task
- If password is correct → login, else → error
Syntax
if condition:
# True block
else:
# False block
Example 1
num = 10
if num % 2 == 0:
print("Even")
else:
print("Odd")
Output:
Even
Example 2
age = 15
if age >= 18:
print("Adult")
else:
print("Minor")
Output:
Minor
Explanation
- num % 2 == 0 → checks if number is even
- age >= 18 → checks age condition
- Based on True/False, Python executes one block
Common Beginner Mistakes
- Missing colon (:)
- Wrong indentation
- Using = instead of ==
- Writing unclear conditions
Why if–else is Important
- Helps in decision-making
- Used in real-world programs
- Makes apps and games smarter
- Controls program flow
➤ Key Points
- Always has two outcomes
- Only one block executes
- Improves decision-making logic
➤ Tips
- Use for binary decisions (Yes/No)
- Avoid writing long conditions
- Keep else block meaningful