It is a Decision making statement and there are three keyword
- if
- else
- elif
Syntax -
if condition:
body
else:
body
if condition:
body
- if and else are similar in some other programming language like C, C++, java but elif is new keyword in python which is used at the time of nested else if
like if we replace above code with elif then :-
if condition:
body
elif condition:
body
program -
i=2
#first
if i>1 and i<4:
print("If condition")
else:
print("Else condition")
if i==2:
print("i is "+i)
#second
if i>3 and i<4:
print("If condition")
elif i==2:
print("i is "+str(i))
If condition
i is 2