Page 126 - TechPluse_C7_Flipbook
P. 126

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  (x < 5) or (x < 2)             True
                                       is 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:






















               124      Premium Edition-VII
   121   122   123   124   125   126   127   128   129   130   131