Conditional statements in Python

A guide to understanding if, else, elif statements in python

Conditional statements help in the control flow. It allows a certain code to execute only when a particular condition has been met.

To control this flow of logic, the keywords given below are used:

  1. if
  2. elif
  3. else

Control flow syntax makes use of colons and indentation. Indentation means whitespace.


if condition1:
elif condition2:

‘if’ keyword

>>> if 45>10:
print("45 is greater than 10")

‘else’ keyword

>>> num1 = 45
>>> num2 = 10

‘elif’ keyword

num1 = 5
num2 = 5

There can be multiple ‘elif’ statements.

Refer to the notebook here.

Beginner-level books to refer to learn Python:

Advance-level books to refer to learn Python:

Reach out to me: LinkedIn

Check out my other work: GitHub