Note that this site is in currently in version 1.0.0-alpha.   Some functionality may be limited.

if-Statement

If-statements check whether a statement meets a certain condition, and are used to write code that “makes decisions”. They start with if followed by a condition which is evaluated to be either true or false. If it’s true, the block after the colon (:) is run. If it’s false, the block under the else: is run.

weather = "sunny"
if weather == "sunny":
    print("Bring your shades")
elif weather == "rainy":
    print("Bring your umbrella")
else:
    print("I don't know what you should bring! I'm just a little program...")

Readings

if-statements and conditionals
More detailed explanation of if-statements and conditionals on Real Python.

Tutorials

Tutorial
Quick explanation of if-statements from w3schools.

Lessons referring to this term