Page 131 - Plus_V2.2_C7_Flipbook
P. 131
Program 2: To demonstrate the 'if' statement.
On running the above program, we get the following output:
The if…else Statement
The if…else statement checks for a condition. If the condition evaluates to True, the indented block
following the if statement is executed, otherwise the indented block after the else statement is
executed. The syntax of the if…else statement is given below:
Syntax:
if (Test Expression):
Indented block
else:
Indented block
Test Expression
False
True
Body of if Body of else
Statement just below if…else
Conditional Statements in Python 129

