Conditional Statements in Python

In this tutorial, we will look at conditional statements. Like other programming languages, similarly, we have in python i.e, if, else if, else.

Syntax:

1. Simple if and else

if (condition_check):
execute this part
else:
execute this part

2. Simple but with three conditions

if (condition_check):
execute this part

elif (another_condition_check):
execute this part

else:
execute this part

3. Nested conditional statements

if (condition_check):
execute this part

else:
if (second_condition_check):
execute this part
else:
execute this part

Let’s see with examples. Here will consider the example of student scoring between good, average and worst.

Using marks of students tells in which category he/she lies


Using conditional statements

Using nested conditional statements

Close Menu