Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 123 - 2609_Logiccode
P. 123

    The assignment operators are described in the following table:

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

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

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

                          %=      Modulus          It  takes  modulus  of two  operands  and  assigns  the  x %= 3
                                  assignment       result to left operand. x%=3 is equivalent to x=x%3.
                          //=     Floor division   It performs floor division on operators and assigns the  x //= 3
                                  assignment       value to the left operand. x//=3 is equivalent to x=x//3.

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

                     Program: To perform all the assignment operation.

                                                                                                      More on Python  121

| 118 119 120 121 122 123 124 125 126 127 128 |