Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python elif Keyword

The Python elif keyword is used to create conditional statement which adds more conditions in if-else statement. The program first checks if condition. When found false, then it checks elif conditions. If found false, then else code block is executed. Please see the syntax.


if condition:
elif condition:

Flow Diagram:

Python If-elif-else Loop

In the example below, else statement is used to print a message when all if and elif conditions result false.

i = 16
if  i > 25:
  print(i," is greater than 25.") 
elif i <=25 and i >=10:
  print(i," lies between 10 and 25.") 
  print(i," is less than 10.")

The output of the above code will be:

16 lies between 10 and 25.

❮ Python Keywords