Learnmonkey Learnmonkey Logo
× Warning:

The tutorial you are reading is currently a work in-progress.

Python If/Else

What are if and else Statements?

When we are coding, we often want some code to be run only when condition is met. This can be implemented using if and else statements, which sound like exactly what they mean. We'll go into more detail later.

The if statement

The else statement

The elif statement

The pass statement

In Python, if statements can't be empty so we use the pass statement to tell Python to do nothing so that Python won't raise an error:


a = 10
b = 50
if b > a:
    pass