Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 130 - 2626_South Point_C-7
P. 130

    The if Statement

                      The if statement is the simplest conditional statement. Here, a statement or a collection of statements
                      within the if block is executed only if a certain condition or expression evaluates to True. If the condition
                      evaluates to False, then the control of execution is passed to the next statement after the if block. The
                      syntax of the if statement is given below:

                      Syntax:
                                                                                                                  False
                      if (Test Expression):                                                   Test Expression
                          Indented statement block

                      # if block ends here                                                             True

                                                                                                 Body of if
                                            Tech Fact

                        In Python, the non-zero value is interpreted as true.
                                None and 0 are interpreted as false.                       Statement just below if

                       Program 1: To check whether a given number is positive.

                      On running the above program, we get the following output:

                                                                                                 Tech Fact
                                                                                        In python, the default value of
                                                                                               boolean is 'True'.

                      128   Premium Edition-VII

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