Python If Elif and Else Statements
This is an conditional statement of python programming. that are normally used to select a decision at current situation and execute instruction. condition is depend upon given expression. if condition are valid then executed of select statement. this process are change the flow of program execution. that is as follows.
If statement are check given expression result if result are not zero or not false then control are enter the condition block (if block) and executes block instructions.
so that is an condition execution statement. let take one example.
if(1>-1): print("1 is greater of -1") #statements no1=10 no2=20 if(no1!=no2): print(no1,"is not equal to ",no2) #statements if(no1==30): print("no1 is 30") #statements
1 is greater of -1 10 is not equal to 20
This is similar to if statement behaviour. it will work when previous binding if or elif condition are fail. that is also check of a given expression is valid or not. for example.
o1=6 no2=6 if(no1>no2): print(no1,"Is Greater Then",no2) elif(no1==no2): #expression(no1==no2) print(no1,"Are Equal To",no2) elif(no1<no2): #expression(no1<no2) print(no1,"Is Less Then",no2)
6 Are Equal To 6
else statement is condition less statement. it will automatic execute when previous defined condition (if or if elif pair) are not valid.
if(5>=7): print("5>=7") else: print("5<7")
else are also use in while loop situations.
no1=90 while(no1<10): print(no1) no1+=1 else: print("Else Condition")