Python elif Keyword (2024)

❮ Python Keywords

Example

Print "YES" if the variable i is a positive number, print "WHATEVER" if i is 0, otherwise print "NO":

for i in range(-5, 5):
if i > 0:
print("YES")
elif i == 0:
print("WHATEVER")
else:
print("NO")

Try it Yourself »

Definition and Usage

The elif keyword is used in conditional statements (if statements), and is short for else if.

Related Pages

The if keyword.

The else keyword.

Read more about conditional statements in our Python Conditions Tutorial.

❮ Python Keywords

W3schools Pathfinder

Track your progress - it's free!

Python elif Keyword (2024)
Top Articles
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 6072

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.