elif
KeywordPython 2.0+Beginner
Short for 'else if'; adds another condition to an if chain
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
score = 85 if score >= 90: grade = "A" elif score >= 80: grade = "B" elif score >= 70: grade = "C" elif score >= 60: grade = "D" else: grade = "F" print(f"Score {score} = Grade {grade}") # Temperature ranges temp = 22 if temp < 0: print("Freezing") elif temp < 10: print("Cold") elif temp < 20: print("Cool") elif temp < 30: print("Warm") else: print("Hot")
elif (else if) lets you test multiple conditions in sequence. Only the first matching branch runs.
Try in PlaygroundTags
languagesyntaxcorecontrol-flowconditional