Page 105 - TP_Play_V2.1_class6
P. 105

The result of the above program is:

                     Output

                  13
                  5
                  36
                  2.25
                  2
                  1
                  6561



                 Assignment Operators

                 The assignment operators are used to assign the value of the right expression to the left operand.

                 The assignment operators are described in the following table:


                  Operator        Name                                Description                          Example

                                               It assigns the value of operand on the right side to
                      =       Assignment                                                                     x = 5
                                               the left side operand.

                                               It adds right operand to the left operand and assigns
                              Addition
                     +=                        the result to left operand. x+=3 is equivalent to            x += 3
                              assignment
                                               x=x+3.

                                               It subtracts right operand from the left operand and
                              Subtraction
                     –=                        assigns the result to left operand. x–=3 is equivalent       x –= 3
                              assignment
                                               to x=x–3.
                                               It multiplies right operand with the left operand and
                              Multiplication
                     *=                        assigns the result to left operand. x*=3 is equivalent to    x *= 3
                              assignment
                                               x=x*3.
                                               It divides left operand with the right operand and
                              Division
                     /=                        assigns the result to left operand. x/=3 is equivalent       x /= 3
                              assignment
                                               to x=x/3.

                              Remainder        It takes modulus of two operands and assigns the
                     %=                                                                                     x %= 3
                              assignment       result to left operand. x%=3 is equivalent to x=x%3.

                                               It performs floor division on operators and assigns
                              Floor division
                     //=                       the value to the left operand. x//=3 is equivalent to        x //= 3
                              assignment
                                               x=x//3.

                                               It performs exponential (power) calculation on
                              Exponentiation
                     **=                       operators and assigns the value to the left operand.         x **= 3
                              assignment
                                               x**=3 is equivalent to x=x**3.






                                                                        Introduction to Programming Python       103
   100   101   102   103   104   105   106   107   108   109   110