Branching in Python
Introduction
The simplest if statement consists of four parts:
- The if operator
- An expression that can be True or False
- The operator:
- 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