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.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s