Python-if-statement .

In this session i have discussed if statement in Python .


If statement is a decision making and branching statement in Python . It is following types .

IF statement .

IF-Else statement .

Nested IF statement .


IF-Statement :

If statment is a powerful decision making and branching statment . It is allow to evaluate the specified condition if condition is true then the statement inside the if will be executed other wise control transfer to next statement .

If-statement-syntax :

mvc image

Example : Write a python program that check the age for voting .

age=19
if(age>17):
    print("Valid for vote")
 
    OUTPUT : Valid for vote
    


Example : Write a python program that check the even number .

x=4;
if(x%2==0):
    print("Even Number")
    
    OUTPUT : Even Number
    


Example : Write a python program that check the odd number .

x=5;
if(x%2!=0):
    print("Odd Number")
          
    
   OUTPUT : Odd Number
   

Welcome to AndroidATPoint.

back image                     next image