Page 179 - Computer Science V2.0 Class 11
P. 179

Operator        Operation                     Explanation                          Examples
                      -=       Subtraction and    The operator subtracts the value on the RHS  >>> b -= 2
                               assignment         of the operator  from the value on the LHS  >>> b
                                                  of the operator and assigns the result to the      3
                                                  operand on the  LHS of the  operator.  Note  >>> c -= 8 // 4
                                                  that the expression on the RHS is evaluated   >>> c
                                                  before applying  -=                            -4

                      -=       Multiplication  and  The operator multiplies the value on the LHS  >>> b *= 3
                               assignment         of the operator by the value on the RHS of  >>> b
                                                  the operator and  assigns  the  result to the       15
                                                  operand  on  the LHS  of  the operator.  Note   >>> c *= 5 + 3
                                                  that the expression on the RHS is evaluated
                                                                                             >>> c
                                                  before applying *=
                                                                                                 -16
                      /=       Division and       The operator divides the value on the LHS of  >>> a /= 4
                               assignment         the operator by the value on the RHS of the  >>> a
                                                  operator and assigns the quotient (float) to       2.5
                                                  the operand on the LHS of the operator. Note   >>> a /= 2 + 3
                                                  that the expression on the RHS is evaluated
                                                                                             >>> a
                                                  before applying /=
                                                                                                 2.0
                      %=       Modulus and        The operator divides the value on the LHS of  >>> a %= 3
                               assignment         the operator by the value on the RHS of the  >>> a
                                                  operator and assigns  the remainder to the      1
                                                  operand on its left. Note that the expression  >>> a %= 2 + 4
                                                  on the RHS is evaluated before applying %=   >>> a
                                                                                                 4
                      //=      Integer division and  The operator divides the value on the LHS of  >>> a //= 3
                               assignment         the operator by the value on the RHS of the  >>> a
                                                  operator  and  assigns  the  quotient  (int)  to      3
                                                  the operand on the LHS of the operator. Note  >>> c //= 2
                                                  that the expression on the RHS is evaluated   >>> c
                                                  before applying //=                            -1

                                                                                             >>> a //= 1 + 3
                                                                                             >>> a
                                                                                                 2
                      **=      Exponentiation and  The operator computes  (operand on the LHS  >>> b **= 3
                               assignment         of **=)** (operand on the RHS of **=)  and  >>> b
                                                  assigns the result to the operand on the LHS      125
                                                  of the operator. Note that the expression on  >>> c **= 2 * 3
                                                  the RHS is evaluated before applying **=.  >>> c
                                                                                                 64
                 7.5.4 Logical Operators
                 A logical value is True or False. The logical operators yield True or False, depending upon the value of logical
                 operands on either side. A value other than 0 and None evaluates to True while zero evaluates to False. Therefore,
                 1, "bb",  and -1 are interpreted as  True but 0  and None are interpreted as False. There are three logical
                 operators: and, or, and not. Note that all three operators are keywords and are used in lowercase only. Further,
                 in an expression, the precedence of the operators in decreasing order is: not, and, or. These operators may be
                 used to express relationships between relational expressions. For detailed description of these operators, see Table
                 7.4: Logical Operators.


                                                                                             Data Types and Operators  165
   174   175   176   177   178   179   180   181   182   183   184