Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 131 - 2626_South Point_C-7
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

| 126 127 128 129 130 131 132 133 134 135 136 |