As long as the expression given by these control statements is not true, then it is its own statement; does not execute.
If the expression in true if statement is true then it executes its statement and if the expression is false then else statement; execute.
Syntax for if_else Statement
if expression:if_statement (s)
else:
else_statement (s)
Example for if_else Statement
1.Source Code:
x = 4y = 4
if (x <y):
print ("x is less than y")
else:
print ("x is greater than or equal to y")
Output:
x is greater than or equal to yif else statement in python |
Example for if_else Statement
2.Source Code:
x = 3y = 6
if (x <y):
print ("x is less than b")
else:
print ("x is greater than or equal to y")
Output:
x is less than yif else statement |
0 Comments