Python Decision Making Statements

In Python, decision making statements are those that decide whether a block of statements has to execute or not based on a condition. Decision making statements are also called Conditional Statements.

In this tutorial, we will learn about different decision making statements available in Python.

Tutorials

There are three decision making statements in Python. The following tutorials detail about these.

ADVERTISEMENT
  • Python – If This tutorial covers the syntax and examples for If statement.
  • Python – If Else This tutorial covers the syntax and examples for If-Else statement.
  • Python – Elif This tutorial covers the syntax and examples for If-Elif statement.

If Statement

If statement is the simplest of decision making statements. It contains a condition and a block of statements. If the condition is True, interpreter executes the block of statements, else not.

In the following program, we print a message to user if number n is positive.

Example.py

a = 5

if a > 0 :
    print('a is positive.')
Try Online

Output

a is positive.

If-Else Statement

If-else statement contains a condition and two block of statements: if-block and else-block. If the condition is True, interpreter executes if-block, or if the condition is False, interpreter executes else-block.

In the following program, we print a message to user if number n is positive or not.

Example.py

a = -5

if a > 0 :
    print('a is positive.')
else :
    print('a is not positive')
Try Online

Output

a is not positive

Elif Statement

Elif statement is a ladder of if-else statements.

In the following program, we print a message to user if number n is positive, or negative or zero.

Example.py

a = 5

if a == 0 :
    print('a is zero.')
elif a > 0:
    print('a is positive.')
elif a < 0:
    print('a is negative.')
Try Online

Output

a is positive.

Conclusion

In this Python Tutorial, we learned different types of decision making statements in Python, and also different scenarios where these decision making statements can be used, with examples.