Codzy

Conditions: if, elif, else

A condition lets you run code only if something is true. You write if, the condition, then a colon :. The lines below are shifted by 4 spaces: that's indentation.

elif tests another condition if the first one is false, and else runs if none is true. To compare, use == (equal), != (not equal), <, >, <= and >=.

temperature = 28
if temperature > 30:
    print("Hot")
elif temperature > 15:
    print("Nice")
else:
    print("Cold")

Start the lesson