Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 89 - 2619_PlusGPT V2.1_C-8
P. 89

    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:

                                                                                        Conditional Statements in Python  87

| 84 85 86 87 88 89 90 91 92 93 94 |