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