Elif Statements

The elif statement is an “else if” statement following either an if statement or another elif statement. It’s condition is checked only if all previous conditions were False.

An elif statement consists of the following:

  • The elif keyword
  • A condition
  • A colon
  • Starting on the next line, an indented block of code
if name == 'Alice':
    print('Hi, Alice.')
elif age < 12:
    print('You are not Alice, kiddo.')
else:
    print('Hello, stranger.')

elif statements can be in a chain. If an elif statement condition is True all of the statements following it in the chain are skipped. Order does matter.