Page 112 - Plus_V2.2_C6_Flipbook
P. 112

The output of the above program is:























                       Logical Operators

                  Logical operators are used to evaluate and decide. Python supports the following logical operators:

                    Operator Name Description                                     Example (x=2)              Output

                       and       AND  It returns true, if both operands are       (x < 5) and (x < 10)        True
                                        true.
                        or        OR    It returns true, if one of the operands is  (x < 5) or (x < 2)        True
                                        true.
                        not      NOT    It reverses the result, returns false, if   not [(x < 5) and (x < 10)]  False
                                        the result is true or vice versa.


                   Program 3: To perform all the logical operators.
















                  The result of the above program will be:



















                  110   Premium Edition-VI
   107   108   109   110   111   112   113   114   115   116   117