Python Elif

If ...elif....else statements are used for more than one condition. Sometimes we want to execute only one block out of three or four blocks. There can be any number of 'elif clauses' after the 'if statement' and before the 'else clause'.


Syntax of Elif

if condition:
   block
elif:
    block
else:
    block

Elif is used in multiple expressions. In this, if the expression within the if statement is true, then the statements within the if are executed, otherwise it checks the condition of the next elif block and if the condition within elif block is false then it prints the block of else statement.

Example of Elif

>>> print("Please Enter a Number")
Please Enter a Number
>>> value = input()
34
>>> if(value < 0):
	print("Number is negative")
elif value == 0:
	print("Number is zero")
else:
	print("Number is positive")
	print("Done")

	
Number is positive
Done

Python else if

Output of Elif Statement
Python if statement





Read more articles


General Knowledge



Learn Popular Language