Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 125 - 2612_Digimind
P. 125

    Example
                       Operator          Name                 Description              (x = 5, y = 3)       Output

                                                      Returns True if both operands
                            ==       Equal to                                               x == y            False
                                                      are equal.

                                                      Returns True if both operands
                            !=       Not equal to                                           x != y            True
                                                      are not equal.

                                                      Returns True if the left
                            >        Greater than     operand is greater than               x > y             True
                                                      the right.
                                                      Returns True if the left
                            <        Less than        operand is less than the              x < y             False
                                                      right operand.

                                                      Returns True if the left
                                     Greater  than
                            >=                        operand is greater than              x >= y             True
                                     or equal to
                                                      or equal to the right.
                                                      Returns True if the left
                                     Less than or
                            <=                        operand is less than or              x <= y             False
                                     equal to
                                                      equal to the right operand.

                     To demonstrate the use of all relational operators.

                         Program4.py

                      File  Edit  Format   Run    Options  Window     Help

                      # Assign values to variables
                      x = 5
                      y = 3

                      # Equal to (==)
                      print("x == y:", x == y)

                      # Not equal to (!=)
                      print("x != y:", x != y)
                      # Greater than (>)
                      print("x > y:", x > y)                                             Output
                      # Less than (<)                                                  x == y: False
                      print("x < y:", x < y)
                                                                                       x != y: True
                      # Greater than or equal to (>=)                                  x > y: True
                      print("x >= y:", x >= y)                                         x < y: False

                      # Less than or equal to (<=)                                     x >= y: True
                      print("x <= y:", x <= y)                                         x <= y: False

                                                                                        Tokens and Data Types in Python  123

| 120 121 122 123 124 125 126 127 128 129 130 |