Python ยท Lesson 3 of 5

๐Ÿšฆ Making decisions with if

Run different code depending on a condition.

if checks a condition. If it is true, the indented lines run. else runs when it is false.

marks = 72
if marks >= 60:
    print("You passed! ๐ŸŽ‰")
else:
    print("Keep practising!")
OUTPUTYou passed! ๐ŸŽ‰

Use == to check if two things are equal, != for not equal, and > < >= <= to compare.

๐Ÿ’ก The lines inside if must be indented (moved right) by 4 spaces.

โœ๏ธ Your turn

Open this example in the playground, change it and run it.

โ–ถ Try it yourself

๐Ÿง  Quick quiz

Which sign checks if two values are equal?