Python Elif
elif adds another mutually exclusive branch to an if chain. Python chooses the first condition that passes and skips later branches.
Understand the idea
Order the conditions so a broad rule does not hide a more specific rule. Separate if statements are different: several of them can run in one pass. Use an if/elif chain when the result should belong to exactly one category.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
stock = 8
if stock == 0:
print("Sold out")
elif stock < 10:
print("Low stock")
else:
print("Ready")
Read the result
The result is Low stock. The zero test has priority over the broader under-ten test.
Try one change
Add a high-stock category and test every boundary in the resulting decision chain.