If…Else Statement in Python

In any programming language conditional (If…Else) statement is very much important and even you can not imagine the programming language without it. Let’s see the structure of If…Else statement in Python.

If Statement Example:

input = 200
if input%2 == 0:
    print(input," is an even number.")

If Else Statement Example:

input = 200
if input%2 == 0:
    print(input," is an even number.")
else:
    print(input," is an odd number.")

If Else If Statement Example:

a = 200
b = 300
if a < b:
    print("a is smaller than b")
elif a == b:
    print("a and b are equal")
else:
    print("a is greater than b")

In this tutorial, I have shown how to write If…Else statement in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.

Add a Comment