Page 117 - ComputerGenius_V2.1_Class8
P. 117

Assignment Operators

                 Assignment operators (=), are used to assign values to variables. It assigns values of the right-side
                 operands to the left-side operands.

                 Example:
                 a=5
                 This is a statement assignment that assigns value ‘5' to the variable ‘a’ on the left.

                                                                Notes


                               ‘5=a’ is an incorrect assignment statement, as the values are assigned
                               from the right side to the left side.





                 Comparison Operators
                 Comparison  operators  are  the  operators  that  compare  the  values  on  either  side of the  symbol.

                 Depending on their operation, these checks if the two operands satisfy the given condition. Then
                 return either True or False based on the result.

                                                                                            Example
                  Operator    Name         Description                                                      Output
                                                                                            (x=8 and y=6)
                      ==      Equal to     It checks if the  values  of two  operands  are  x == y          False
                                           equal or not. If the values are equal, then the

                                           condition becomes true.
                      !=      Not equal    It checks if the  values  of two  operands  are  x != y          True
                              to           equal or not. If the values are not equal, then
                                           the condition becomes true.

                      >       Greater      It checks whether the value of the left operand  x > y           True
                              than         is greater than the value of the right operand.
                                           If it is, the condition evaluates to true.

                      <       Less than    It checks whether the value of the left operand  x < y           False
                                           is less than the value of the right operand. If it

                                           is, the condition evaluates to true.

                      >=      Greater      It checks whether the value of the left operand  x >= y          True
                              than or      is greater than or equal to the value of the right
                              equal to     operand. If it is, the condition evaluates to true.

                      <=      Less than    It checks whether the value of the left operand  x <= y          False
                              or equal to  is less than or equal to the value of the right
                                           operand. If it is, the condition evaluates to true.





                                                                                            Basics of Python  115
   112   113   114   115   116   117   118   119   120   121   122