elif

noun

say it: “EL-if” /ˈɛlɪf/

Short for "else if": in Python, it checks another condition when the ones above it were false, and Python runs the first branch that's true.

What does elif do?

elif (short for "else if") checks another condition when the ones above it were false. Python stops at the first one that is true.

score = 85
if score >= 90:
    print("A")
elif score >= 80:
    print("B")  # this one runs
elif score >= 70:
    print("C")

In a sentence

  • “Only one branch runs, even when two elif conditions are true.”
  • “The grade uses if for an A and elif for a B and a C.”

Level: Novice · More Python terms at this level

Updated