else

noun

say it: “ELSE” /ˈɛls/

In Python, the part of an if statement that runs when none of the if or elif conditions above it were true.

What does else do?

else runs its block when none of the if or elif conditions above it were true.

balance = 20
if balance >= 50:
    print("Purchase approved")
else:
    print("Not enough money")  # this one runs

In a sentence

  • “Every if doesn't need an else; add one when there's something to do otherwise.”
  • “If the balance is too low, the else branch prints "Not enough money".”

Level: Novice · More Python terms at this level

Updated