Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 127 - 2609_Logiccode
P. 127

    The following conditional statements are available in Python:

                       if statement                   if...else statement

                       Nested if statement            if…elif…else ladder

                               IF STATEMENT                                                      Start

                     The  if statement  is  the  simplest  conditional  statement.  Here,
                     a statement or a collection of statements within the if block is                            False
                                                                                               if condition
                     executed only if a certain condition or expression evaluates to
                     True. Otherwise, the control of execution is passed to the next                True
                     statement after the if block.                                        Statements in if block

                     Syntax:                                                                    execute

                     if (condition):
                                                                                                 Stop
                         Indented statement block

                     # if block ends here

                         PURE
                         FACT        In Python, the non-zero value is interpreted as True. None and 0 are interpreted as False.

                     Program: To check whether a given number is positive.

                     On running the above program, you will get the following output:

                                                                                                      More on Python  125

| 122 123 124 125 126 127 128 129 130 131 132 |