Branch code execution with the if...elif...else statement in Python

Visual Studio

Use the if statement Boolean expressions with comparison and logic operators to express decision logic.

Learning objectives

In this module, you will:

  • Use the if ... elif ... else statements to add decision logic to your Python code.
  • Understand the Boolean data type and what it represents in Python.
  • Compose Boolean expressions by using a rich set of comparison and logic operators.


  • You should have your Python development environment already set up and know how to create, edit, and execute Python code stored in a .py file.
  • You should have exposure to the use of input and output functions like print() and input().
  • You should know how to create and assign values to variables.