Python Fundamentals / Making decisions
Lesson 13 of 38
elif and else
elif checks another condition if the first was False, and else catches everything left over. Python checks them top to bottom and stops at the first True one.
Key points
- Only one branch runs
- Order checks from most to least specific
- else has no condition
temp = 45
if temp > 40:
print("Very hot")
elif temp > 25:
print("Warm")
else:
print("Cool")Quiz · +10 XP
If temp is 30 in the code above, what prints?
Log in to save progress and earn XP.