Python Nested If

This is the complex control flow logic. In Nested-If-Else, we can write multiple if-elif-else in one if-elif-else. This is used for multiple decision making.


Syntax of Nested If

if condition:
	block
	if condition:
		block
	elif:
		block
	else:
		block	
elif:
    block
else:
    block	


Example of Nested If

>>> if(value < 0):
	print("Value is negative")
elif(value > 0):
	print("Value is positive")
	if(value < 50):
		print("Value is less than fifty")
	elif(value == 50):
		print("Value is equal to fifty")
	else:
		print("Value is greater than fifty")
else:
	print("Value is Zero")

	
Value is positive
Value is greater than fifty


Python nested if

Output of the above code
Python nested if statement





Read more articles


General Knowledge



Learn Popular Language