Write an if/elif/else chain that grades a score, and explain what happens once a branch is taken.
An if statement runs its body when the condition is truthy. When that happens, the whole chain is finished. Python does not carry on to the elif branches, and it does not run the else either.
score = 75
if score >= 90:
grade = 'A'
elif score >= 75:
grade = 'B'
elif score >= 60:
grade = 'C'
else:
grade = 'F'
print(grade) # B
The chain is evaluated strictly from the top. Python tests score >= 90, which is false, and then it tests score >= 75, which is true. It binds grade to B and skips the remaining branches completely. Only one branch ever runs.
Two structural details are worth mentioning in an interview. The elif is only a short way of writing else: if, so you can have as many of them as you like, but a plain if can never come after an elif. The chain has to start with if. And the else branch is optional, so a chain may simply end with no else and do nothing when nothing matches.
The condition itself is tested for truthiness and not for equality with True. A non-empty string, a number that is not zero, and a collection that is not empty are all truthy. That makes if value: a test for emptiness rather than a test for presence, so if a value may legitimately be zero or an empty list, write if value is not None: instead.
One last practical point is that Python has no switch statement, so a chain of if and elif on the same variable is the usual way to express a choice between many values. Python 3.10 added the match statement as a more expressive alternative.