elif — Expert Examples
Short for 'else if'; adds another condition to an if chain
elif bytecode: sequential testing
How elif compiles to chained jumps.
python
import dis def grade(score): if score >= 90: return "A" elif score >= 80: return "B" elif score >= 70: return "C" else: return "F" dis.dis(grade) # Each elif compiles to: # COMPARE_OP, POP_JUMP_IF_FALSE -> next elif # There is NO optimization to a jump table # Each condition is tested sequentially
elif compiles to a chain of compare + conditional jump instructions. Unlike switch/case in C, there is no jump table — each condition is evaluated one by one until a match is found.
Want to try these examples interactively?
Open Expert Playground