If and Else Statement in Python

If-else statement in Python programming allows you to control and execute the specific block of code if the condition is true, otherwise, execute the else block.

Program Using If and Else Statement

Program

num = int(input("Enter a Number Less then OR Equal to 10: "))
     #user enter value converting to Integer and assigning to 'num'.
if num <= 10: #if 'num' value is less then or Equal to 10 then
    print("What an obedient servant you are!") #print this.
else: #if not mean 'num' value greater then 10 then
    print("Invalid Entry U Enter Greater then 10") #print this.
Output
Enter a Number Less then OR Equal to 10: 5
What an obedient servant you are!

Program Searching Number in Numbers

Program

if 3 in (1, 3, 4, 5): #if '3' value is present then
    print("There is 3 Number.") #print this.
else: #if not then
    print("There is No any 3 Number.") #print this.
Output
There is 3 Number.

Program Searching Litter in String

Program

name = input("What is your name: ")
if 's' in name: #if 'name' value have 's' then
    print("Your name contains the letter s.") #print this.
else: #if not then
    print("Your name does not contain the letter s.") #print this.
Output
What is your name: Bilal
Your name does not contain the letter s.