First page Back Continue Last page Overview Graphics

if statement

The if statement is a way to make sure that parts

of the code will only be executed under certain

conditions.

if condition: # statements else:

# statements

If the condition following the if is evaluated to True,

the first nested block will be executed. In case of False the second nested block

will be executed, i.e. the one following the else.

if condition1:

# statements

elif condition2:

# statements

else:

# statements

The else-part of the if statement may contain a nested if statement.

In this case we can write “elif” instead of “else if”.