Conditional statements in Python

  1. if
  2. elif
  3. else

Syntax:

if condition1:
statement1
elif condition2:
statement2
else:
statement3

‘if’ keyword

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

‘else’ keyword

>>> num1 = 45
>>> num2 = 10
>>> if num1>num2:
print("num1 is greater")
else:
print("num2 is greater")
num1 is greater>>> num1 = 5
>>> num2 = 10
>>> if num1>num2:
print("num1 is greater")
else:
print("num2 is greater")
num2 is greater

‘elif’ keyword

num1 = 5
num2 = 5
>>> if num1>num2:
print("num1 is greater")
elif num1==num2:
print("both numbers are equal")
else:
print("num2 is greater")
both numbers are equal

Beginner-level books to refer to learn Python:

Advance-level books to refer to learn Python:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jayashree domala

Jayashree domala

157 Followers

Self-driven woman who wishes to deliver creative and engaging ideas and solutions in the field of technology.