Page 305 - Artificial Intellegence_v2.0_Class_9
P. 305

Augmented Assignment Operators
            Augmented assignment operators are those operators which take the value of the operand on the right side,
            perform an operation and assign the result to the operand on the left side. These operators are also known as
            shorthand assignment operators. For example, if a=10 then a+=5 is the same as a=a+5.


            Python provides the following augmented assignment operators:

                   Symbol                          Purpose                         Example            Output

                                                                                     a = 5
                                 Adds first and then assigns the result to the left-  b = 10            15
                     +=
                                 hand side operand.                                 a += b              20

                                                                                    a += 5
                                                                                     a = 5
                                 Subtracts first and then assigns the result to the
                      -=                                                            b = 10              -5
                                 left-hand side operand.
                                                                                    a -= b
                                 Multiplies first and then assigns the result to the   a = 5
                      *=                                                                                25
                                 left-hand side operand.                            a *= 5

                                 Divides first and then assigns the result to the   b = 10
                      /=                                                                                2.0
                                 left-hand side operand.                            b /= 5
                                                                                     a = 5
                                 Floor division first and then assigns the result to
                     //=                                                            b = 10               2
                                 the left-hand side operand.
                                                                                    b //= a
                                                                                     a = 5
                                 Remainder  of  a  number  first  and  then  assigns
                     %=                                                             b = 10               5
                                 the result to the left-hand side operand.
                                                                                    a %= b
                                                                                     a = 2
                                 Exponential of a number first and then assigns
                     **=                                                             b = 4              16
                                 the result to the left-hand side operand.
                                                                                    a **= b


                           Reboot

                 1.  What is the use of ** operator?


                 2.  Define the relational operators.


                 3.  Give an example to use **= operator?










                                                                                   Introduction to Python  303
   300   301   302   303   304   305   306   307   308   309   310