Branch code execution with the if and else statements in Python

Beginner
Developer
Student
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.

Prerequisites

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