Python: 10 Conditions – elif Statement for If Statements

The elif statement is short for else if. This is used for giving multiple options with an if statement.

age = 25
if age < 5:
elif age <= 12:
elif age < 20:

In the example above the age is set to 25. (You would usually have this being able to be changed by reading input in).

The first if statement checks if the age is under 5. If it is it prints the message “Preschool”.

Otherwise it checks if the age is equal to or less than 12 and prints “Child”

Then it checks if the age is under 20 and prints “Teenager”

Otherwise the age is 20 or more so “Adult” is displayed.

This is shown in the flow chart below

Additional information can be found on W3 Schools.