Branching in Python

Introduction

The simplest if statement consists of four parts:

  1. The if operator
  2. An expression that can be True or False
  3. The operator:
  4. A statement

Syntax:

if expression:
    statement

The simplest statement is pass it does nothing.

if elif else

a = 1961 b = 1945 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b")

Article author: Andrei Olegovich