The other side of the decision
The problem...
You know how to make your code act when a condition is true.
But what happens when it's false? Right now — nothing. The block is skipped and your program moves on in silence.
Sometimes that's fine. Often it's not.
The idea!
Every decision has two sides. if handles the true side. else handles everything else.
No second condition needed. No extra checking. If the if didn't run — else runs.
The syntax
if condition:
# runs if condition is True
else:
# runs if condition is False
else has no condition of its own. It's the fallback — the plan B. In the army, you always have a contingency. Your code should too.
Your first if / else
temperature = 20
if temperature > 30:
print("It's hot outside.")
else:
print("It's not that hot.")
Condition is false — so else runs. One of the two blocks always executes. Always.
A real example
score = 45
if score >= 60:
print("You passed.")
else:
print("You failed. Try again.")
Clean. Complete. Every case is handled.
else is a guarantee
is_logged_in = False
if is_logged_in:
print("Welcome back.")
else:
print("Please log in first.")
With else, your program never goes silent when it shouldn't. One path always runs.
Heads up!
elsehas no condition — it catches everything theifdidn'telsemust always be paired with anif— it can't stand alone- Exactly one of the two blocks runs — never both, never neither
elsealso ends with:and its block is indented
The mindset shift
Stop thinking: "I'll handle the false case later."
Start thinking: "Every decision needs both sides covered."
What you should understand now
elseruns when theifcondition isFalse- It has no condition of its own — it's the default fallback
- With
if / else, exactly one block always runs elsemust be paired with anif— never alone