Page 95 - PlugGPT_V2.0_C7_Flipbook
P. 95

Program 3: To perform all the logical operators

                     Program3.py
                  File  Edit  Format   Run   Options   Window     Help



                  a = True
                  b = False

                  print(a and b)
                  print(a or b)
                  print(not a)
                  print(not b)




                 The result of the above program is:
                     Output

                  False
                  True
                  False
                  True



                 Relational Operator

                 Relational operators are used to compare the value of the two operands and returns True or
                 False accordingly. The relational operators are described in the following table:

                                                                                             Example
                  Operator      Name                       Description                                      Output
                                                                                          (x=8 and y=6)
                     ==         Equal      It checks if the  values of two  operands           x == y       FALSE
                                           are equal or not. If yes, then the condition
                                           becomes true.
                      !=      Not equal It checks if the values of two operands are            x != y       TRUE
                                           equal  or  not.  If the  values are  not  equal,
                                           then the condition becomes true.
                      >        Greater     It checks if the value of left operand  is          x > y        TRUE
                                 than      greater than the value of right operand. If
                                           yes, then the condition becomes true.
                      <       Less than    It checks if the value of left operand is less      x < y        FALSE
                                           than the value of right operand. If yes, then
                                           the condition becomes true.
                     >=        Greater     It checks if the value of left operand is greater   x >= y       TRUE
                                than or    than or equal to the value of right operand.
                               equal to    If yes, then the condition becomes true.

                     <=       Less than  It checks if the value of left operand is less        x <= y       FALSE
                              or equal to  than or equal to the value of right operand.
                                           If yes, then the condition becomes true.



                                                                          Introduction to Programming Python         93
   90   91   92   93   94   95   96   97   98   99   100