Page 127 - TechPluse_C7_Flipbook
P. 127

Relational Operators

                 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           x >= y       True
                               than or     greater than or equal to the value of
                               equal to    right operand. 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.


                  Program 4: To show all the relational operators’ functions.















                 The result of the above program is:




















                                                                                         Introduction to Python      125
   122   123   124   125   126   127   128   129   130   131   132