Tag Archives: nested if statement

Python: Nested if Statement


An if statement within another if statement is known as nested if statement. Similarly, any decision logic can be written within an else statement also.

Have a look at the below example of nested if:

Example

num1=10
num2=20
num3=30
	
if(num1>num2):
	if(num1>num3):
      print("num1 is greater")
	else:
	  print("num3 is greater")
elif(num2>num3):
	print("num2 is greater")
else:
	print("num3 is greater")

Output

num3 is greater

in this above example, one if statement is inside of another if block. It’s good example of nested if statement.