Page 95 - Touchcode_C7_Flipbook
P. 95

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

                       =       Assignment       It assigns the value of operand on the right side to        x = 5
                                                the left side operand.
                      +=       Addition         It adds right operand to the left operand and               x += 3

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

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

                                                equivalent 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.
                      //=      Floor division  It performs floor division on operators and assigns         x //= 3

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

                 Logical Operators

                 Logical operators are used to evaluate and decide. Python supports the following logical
                 operators:


                  Operator      Name                 Description                    Example (x=2)          Output
                      and        AND      It returns true, if both operands  (x < 5) and (x < 10)            TRUE

                                          are true.
                       or         OR      It  returns true, if  one  of  the  (x < 5) or (x < 2)             TRUE

                                          operands is true.
                      not        NOT      It reverses the result, returns false,  not [(x < 5) and (x < 10)]  FALSE
                                          if the result is true or vice versa.


                                                                                              More on Python
                                                                                              More on Python     93
                                                                                                                 93
   90   91   92   93   94   95   96   97   98