← Back to Blog

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!

  • else has no condition — it catches everything the if didn't
  • else must always be paired with an if — it can't stand alone
  • Exactly one of the two blocks runs — never both, never neither
  • else also 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

  • else runs when the if condition is False
  • It has no condition of its own — it's the default fallback
  • With if / else, exactly one block always runs
  • else must be paired with an if — never alone
[ login to bookmark ] // copied! 34 views · 1 min
// resources
Code Example else_statement.py
← prev The first question your code ever asked next → Split the decision. Again.
// 0 comments
// No comments yet. Be the first.
// leave a comment

// Your comment will appear after approval.