Skip to content

Python Elif Statement

Syntax

The elif statement in Python allows for additional conditions to be checked after an initial if condition fails.

if condition1:
# Code to execute if condition1 is true
elif condition2:
# Code to execute if condition2 is true
else:
# Code to execute if none of the above conditions are true

Example

age = 19
if age < 13:
print("You are a child.")
elif age < 20:
print("You are a teenager.")
else:
print("You are an adult.")
# Output: You are a teenager.