elseEasy Examples

Catch-all branch when preceding if/elif conditions are all false

The else branch

Providing a fallback when the condition is False.

python
x = 3
if x > 5:
    print("Greater than 5")
else:
    print("5 or less")

# else with a function
def check_password(pw):
    if len(pw) >= 8:
        return "Strong enough"
    else:
        return "Too short"

print(check_password("abc"))
print(check_password("secure123"))
Expected Output
5 or less
Too short
Strong enough

else runs when the if condition is False. Every if can have at most one else.

Want to try these examples interactively?

Open Easy Playground