Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 127 - 2612_Digimind
P. 127

    ASSIGNMENT OPERATORS
                     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:

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

                                                            Assigns the value of the operand on the
                              =         Assignment                                                         x = y
                                                            right side to the left side operand.

                                                            Adds the right operand to the left
                                        Addition            operand and assigns the result to
                             +=                                                                            x += y
                                        assignment          the left operand. x += y is equivalent
                                                            to x = x + y.

                                                            Subtracts the right operand from the
                                        Subtraction         left operand and assigns the result to
                             -=                                                                            x -= y
                                        assignment          the left operand. x -= y is equivalent
                                                            to x = x - y.

                                                            Multiplies the right operand with the
                                        Multiplication      left operand and assigns the result to
                             *=                                                                            x*=y
                                        assignment          the left operand. x *= y is equivalent
                                                            to x = x * y.

                                                            Divides the left operand by the right
                                        Division            operand and assigns the result to
                             /=                                                                            x /= y
                                        assignment          the left operand. x /= y is equivalent
                                                            to x = x / y.

                                                            Takes the modulus of the left operand
                                        Modulus             by the right operand and assigns the
                             %=                                                                            x %= y
                                        assignment          result to the left operand. x %= y is
                                                            equivalent to x = x % y.

                                                            Performs floor division on the
                                        Floor division      operands and assigns the result
                             //=                                                                           x //= y
                                        assignment          to the left operand. x //= y is equivalent
                                                            to x = x // y.

                                                            Raises the left operand to the
                                        Exponentiation      power of the right operand and
                             **=                                                                          x **= y
                                        assignment          assigns the result to the left operand.
                                                            x **= y is equivalent to x = x ** y.

                                                                                        Tokens and Data Types in Python  125

| 122 123 124 125 126 127 128 129 130 131 132 |