The elif Header in Python

  • If statements may contain only one else header.
  • Thus, if-else statements must be nested to achieve multi-way selection.
  • Python, however, has another header called elif (“else-if”) that provides multi-way selection in a single if statement, shown in Figure.
  • All the headers of an if-elif statement are indented the same amount, thus avoiding the deeply nested levels of indentation with the use of if-else statements.
  • A final else clause may be used for “catch-all” situations.
Design a site like this with WordPress.com
Get started