Python provides the elif
statement in order to add extra conditions to the if
statement. Sometimes it can be also called elif command
in Python. But in reality, the elif is not a command and it is a statement related to the if statement. We can use the elif statement in order to add single or multiple conditions to the existing if statement.
elif Command Usage
Even the elif is not a command and it is a statement we call it as “elif command” in this section to make things more clear for readers. We can use the elif command like below to add single or more conditions.
age = 21
if age>80
print("Age is over 80")
elif age>65
print("Age is between 18 and 65")
elif age>18
print("Age is over 18")
In this example, we use multiple elif commands in order to check the age conditions. We check if the age is above 80 or 65 or 18.