Decision making statements (if, if-else, etc) are used to control the flow of execution of the program according to the condition.
Example – If the condition is true, the block is executed, and if the condition is false, the block is not executed.
In the Python programming language, all non-zero or zero values are assumed to be TRUE, and if they are zero or zero, then they are assumed to be FALSE.
The Python programming language provides the following types of decision statements. Click on the following links for details.
Types of Decision Statements in Python
There are three types of decision statements in Python.
1. if statements
Example of ‘if’ statement in Python
value = 2
if (value == 2):
print('Python basic tutorial.')
Output
Python basic tutorial.
2. if-else statements
Example of ‘if-else’ Statement In Python
value=5
if(value < 5):
print('Less than 5 mangoes are in the basket.')
else:
print('5 or more mangoes are in the basket.')
Output
5 or more mangoes are in the basket.
3. Nested if-else statements
Example of ‘Nested if-else’ statement in python
value=5
if(value < 5):
print('Less than 5 mangoes are in the basket.')
elif(value == 5):
print('5 mangoes are in the basket.')
else:
print('More than 5 mangoes are in the basket.')
Output
5 mangoes are in the basket.