Conditional Control Statements in Python

 

Conditional Control statements

We have 3 conditional control statements in Python

if


# program to understand if condition
def display(a):
if a == 5:
print("a is greater")

a =
5
display(a)

#output
a is greater


if-else


# program to understand if-else condition
def display(a, b):
if a > b:
print("a is greater")
else:
print("b is greater")

a =
5
b = 10
display(a, b)

#output
b is greater


if-elif-else


# program to understand if-else condition
def display(a, b):
if a > b:
print("a is greater")
elif b > a:
print("b is greater")
else:
print("a and b are equal")

a =
5
b = 5
display(a, b)

#output
a and b are equal





Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India