Python

Python If-else statements

If-else is basic control statement in any Programming language. Python if-else statement checks the expression inside “if” parenthesis and executes only when specified condition is true.

Syntax:
if(condition):
<set of statements to be executed>
elif:
<set of statements>
else:
<set of statements>

Note:  Else-if needs to be given as elif in Python and Indentation needs to be taken care properly since python works on Indentation.

Example:

team="csk"
if(team == "csk"):
   print("Captain is MS Dhoni")
elif(team == "rcb"):
   print("Captain is V Kohli")
else:
   print("please give valid team name")
Output:
Captain is MS  Dhoni

Share This Post

Avatar
An Ambivert, music lover, enthusiast, artist, designer, coder, gamer, content writer. He is Professional Software Developer with hands-on experience in Spark, Kafka, Scala, Python, Hadoop, Hive, Sqoop, Pig, php, html,css. Know more about him at www.saikumar.me

Lost Password

Register