Page 77 - TP_Prime_V2.2_Class7
P. 77

The if…elif…else Statement

                 The if...elif...else statement in Python allows us to check multiple conditions in a top-down
                 approach. If the condition in the if statement is true, its block runs, and the rest are

                 skipped. If not, Python checks each elif condition until it finds one that is true.

                                                                         Start
 Prime (Ver. 2.2)-VII  Syntax                                         If condition 1  False       Book 3                    MORE ON PYTHON











                      if (condition 1):                                     True     False
                           if (condition 2):
                                  Indented block 1                    If condition 2              Book 2

 74                 else:                                                   True                                          75
                           Indented block 2
                    else:                                                Book 1

                           Indented block 3


                                                                         Stop


                 Let us see an example of the if...elif...else statement:





































                                                      Using if…elif…else statement
   72   73   74   75   76   77   78   79   80   81   82