An elif clause introduces another condition after if. Python checks it only when earlier conditions are false, then runs the first block whose condition is true. section 14.2
Listing 14.3. Example of a simple if-elif-else conditional statement
num = int(input("Enter a number: ")) #1
if num > 0: #2
print("num is positive") #3
elif num < 0: #4
print("num is negative") #5
else: #6
print("num is zero") #7
A number checker combines if, elif, and else: positive numbers print one message, negative numbers another, and zero uses the final alternative. section 14.2
Remember these rules:
- Begin the decision chain with if; add one or more elif clauses when later conditions are needed. section 14.2
- Only one branch runs, even when several conditions might eventually be true; Python stops at the first true condition. section 14.2
- Use separate if statements when multiple independent actions should run rather than one exclusive choice. section 14.2


