Skip to content
dreamcode
dreamcode
Map
Elif chains
Lesson 10 of 77
+15 XP on finish
PYTHON BASICSChapter 2 · Conditionals and logic

Multiple choices

When you have more than two possibilities, use elif (short for else-if) to check additional conditions. Python checks them in order and runs the first one that is True.

Worked example

How it reads

  • if hour < 12: is checked first
  • elif hour < 18: is checked only if the first condition was False
  • else: runs if none of the conditions above were True
Cloud tip: You can have as many elif blocks as you need, but you can only have one if at the start and one else at the end.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add another elif so 5 or 6 clouds prints Mostly cloudy, then set clouds = 6 to see it.

Press Run to check your work.