Python elif Keyword

❮ Python Keywords


Example

Print "YES" if the variable i is a positive number, print "WHATEVER" if i is 0, otherwise print "NO":

for i in range(-5, 5):
  if i > 0:
    print("YES")
  elif i == 0:
    print("WHATEVER")
  else:
    print("NO")
Try it Yourself »

Definition and Usage

The elif keyword is used in conditional statements (if statements), and is short for else if.


Related Pages

The if keyword.

The else keyword.

Read more about conditional statements in our Python Conditions Tutorial.


❮ Python Keywords

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.