Assignment Operators
Python Assignment Operators:
Assume a = 10 and b = 20 then:
= Simple assignment operator, Assigns values from right side operands to left side operand: c = a + b will assign value of a + b into c
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand: c += a is equivalent to c = c + a
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a
/= Divide AND assignment operator, It divides left operand with the right
operand and assign the result to left operand c /= a is equivalent to c = c / a
%= Modulus AND assignment operator, It takes modulus using two operands and
assign the result to left operand c %= a is equivalent to c = c % a
**= Exponent AND assignment operator, Performs exponential (power)
calculation on operators and assign value to the left operand
c **= a is equivalent to c = c ** a
//= Floor Dividion and assigns a value, Performs floor division on
operators and assign value to the left operand c //= a is equivalent to c = c // a
Comments
Post a Comment