Python If Elif


Elif

The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition".

Example

a = 33
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")
Try it Yourself »

In this example a is equal to b, so the first condition is not true, but the elif condition is true, so we print to screen that "a and b are equal".



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