Page 41 - 2501_KVS_C-8
P. 41

It can also be understood by the given example:
                 E.g. suppose statement A is “Meera is a good girl.”, then if we say NOT A, it will be read as
                 “Meera is not a good girl.”

                 It can also be understood by the following table:


                                                          A             not A
                                                          0                1

                                                          1                0

                 Here, if the value of A is 0 i.e. False, then not A will be 1 i.e. True and if the value of A is
                 1 i.e. True, then not A will be 0 i.e. False.

                 Now, let us take one more example of not operator in python. Just observe and try to
                 understand how it works:

                             Age=14


                             if not (Age >18):
                                     print("Age is less than or equal to 18")
                             else:

                                     print("Age is greater than 18")
                 The example has a variable named Age whose value is initially assigned the value 14. Now,
                 the ‘if’ condition is checking whether the value of the Age variable is not greater than 18,
                 then a message “Age is less than or equal to 18” will be displayed on the output screen.
                 Otherwise, a message “Age is greater than 18” will get displayed if the above condition is
                 False.

                     AND  Operator: “and”  operators work on two(02)  or more than 02  conditions/
                     expressions and it will give the result True only when both the conditions are True. It
                     will give the result False, if any one of the two(02) conditions is False. In python, this
                     operator is used by symbol “&” or keyword “and”.

                     It can also be understood with the help of the following truth table:

                                             A                    B                A and B

                                             0                    0                    0
                                             1                    0                    0
                                             0                    1                    0

                                             1                    1                    1
                 Here, the value of the final expression will be 1 or True only when the value of both
                 conditions A & B are 1 or True.







                                                                     Logical Operators in Python                    39
   36   37   38   39   40   41   42   43   44   45   46