Page 31 - Modular v1.1 Pyhton
P. 31

Clickipedia




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




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


















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




























                     IF…ELSE STATEMENT


                 The  if…else  statement checks for a condition. If              Test Expression
                 the condition evaluates to  True, the indented  block
                                                                                                               False
                 following the if statement is executed, otherwise the                   True
                 indented block after the else statement is executed.
                                                                                   Body of if           Body of else
                 Syntax:

                 if (Test Expression):
                     Indented block
                                                                             Statement just below if
                 else:

                     Indented block

                                                                               Conditional Statements in Python   29
   26   27   28   29   30   31   32   33   34   35   36