Home >>Python Keywords >Python elif Keyword

Python elif Keyword

Python elif Keyword

Python elif keyword is used in conditional statements like if statements, and is short for else if. This keyword is used to add extra conditions to the conditional statements.

Here is an example of Python elif keyword:

for i in range(-5, 5):
  if i > 0:
    print("First Condition")
  elif i == 0:
    print("Else if condition")
  else:
    print("Default Condition")

Output:
Default Condition
Default Condition
Default Condition
Default Condition
Default Conditionv
Else if condition
First Condition
First Condition
First Condition
First Condition
Example 2:

for i in range(100):
  if i > 10:
    continue
  elif i < 10:
    print(i)
  else:
    print("Error")

Output:
0
1

No Sidebar ads