If Else If Statement in Python programming | Hands on coding

If else if ladder statement

Syntax:

if  condition  :
    statement1
elif condition:
    statement2
elif condition:
    statement3
else:
    statement4
  • If Else If Statement is used to test the condition.
  • If Else If Statement executes only one condition at a time.
  • The condition which is true first from the top will execute.

no=7
if no>10:  /*false*/
    print("Hello1")
elif no>5: /*true*/
    print("Hello2")
elif no>0: /*true*/
    print("Hello3")
else:
    print("Helllo4")
/*
 ### Output ###
 Hello2
 because it executes only one condition 
 which becomes true first from top.
 */



no=-5
if no>10:
    print("Hello1")
elif no>5:
    print("Hello2")
elif no>0: 
    print("Hello3")
else:
    print("Helllo4")
/*
 ### Output ###
 Helllo4
 because  all conditions are false.
*/