Python elif Keyword

Example

If the variable i is controversial, print "YES", if i is 0 then print "WHATEVER", otherwise print "NO":

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

Run Instance

Definition and Usage

elif Keyword is used in conditional statements (if statements) and is a shorthand for else if.

Related Pages

if Keyword

else Keyword

Please visit our Python Condition Learn more about conditional statements in the Chinese language.