Decision making statement if else in python by R4R Team

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))



output -

If condition
i is 2



Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!