Page 95 - Information_Practice_Fliipbook_Class11
P. 95
Operator Operation Explanation Examples
= Assignment The operator assigns the value on the RHS of the >>> a = 10
operator to the operand on the LHS of the operator. >>> b = a+b
>>> b
15
+= Addition and The operator adds the value on the RHS of the >>> a += 20
assignment operator to the operand on the LHS of the operator >>> a
and assigns the result to the operand on the LHS of 30
the operator. Note that the expression on the RHS is >>> a += 3*4
>>> a
evaluated before applying +=.
22
-= Subtraction and The operator subtracts the value on the RHS of the >>> b -= 2
assignment operator from the value on the LHS of the operator >>> b
and assigns the result to the operand on the LHS of 3
the operator. Note that the expression on the RHS is >>> c -= 8//4
>>> c
evaluated before applying -=.
-4
*= Multiplication The operator multiplies the value on the LHS of the >>> b*=3
and assignment operator by the value on the RHS of the operator >>> b
and assigns the result to the operand on the LHS of 15
the operator. Note that the expression on the RHS is >>> c *= 5+3
>>> c
evaluated before applying *=.
-16
/= Division and The operator divides the value on the LHS of the >>> a /= 4
assignment operator by the value on the RHS of the operator and >>> a
assigns the quotient (float) to the operand on the 2.5
LHS of the operator. Note that the expression on the >>> a /= 2+3
>>> a
RHS is evaluated before applying /=.
2.0
%= Modulus and The operator divides the value on the LHS of the >>> a %= 3
assignment operator by the value on the RHS of the operator and >>> a
assigns the remainder to the operand on its left. Note 1
that the expression on the RHS is evaluated before >>> a %= 2+4
>>> a
applying %=.
4
//= Integer division The operator divides the value on the LHS of the >>> a //= 3
and assignment operator by the value on the RHS of the operator and >>> a
assigns the quotient (int) to the operand on the LHS 3
of the operator. Note that the expression on the RHS >>> c //= 2
>>> c
is evaluated before applying //=.
-1
>>> a //= 1+3
>>> a
2
**= Exponentiation The operator computes (operand on the LHS of >>> b **= 3
and assignment **=)** (operand on the RHS of **=) and assigns >>> b
the result to the operand on the LHS of the operator. 125
Note that the expression on the RHS is evaluated >>> c **= 2*3
>>> c
before applying **=.
64
Data Types and Operators 81

