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:

[code lang=”python”]
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")[/code]

Output:
Captain is MS  Dhoni

Share This Post

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.24tutorials.com/sai

Lost Password

Register

24 Tutorials