In this tutorial, you will learn about assignment operators in python and assignment operators examples. Assignment operators are used for assigning the value of right operand to left operand. Assignment operators used in python are (+=,-=,*=, /=, etc). If python =A-B the value of A-B then the value will be assigned to python. Python does not have decrement and increment operator. Python assignment operator is simply to assign the value.
OPERATOR |
DESCRIPTION |
SYNTAX |
= |
Assign value of right side of expression to left side operand |
x = y + z |
+= |
Add AND: Add right side operand with left side operand and then assign to left operand |
a+=b a=a+b |
-= |
Subtract AND: Subtract right operand from left operand and then assign to left operand |
|
*= |
Multiply AND: Multiply right operand with left operand and then assign to left operand |
a*=b a=a*b |
/= |
Divide AND: Divide left operand with right operand and then assign to left operand |
a/=b a=a/b |
%= |
Modulus AND: Takes modulus using left and right operands and assign result to left operand |
a%=b a=a%b |
//= |
Divide(floor) AND: Divide left operand with right operand and then assign the value(floor) to left operand |
a//=b a=a//b |
**= |
Exponent AND: Calculate exponent(raise power) value using operands and assign value to left operand |
a**=b a=a**b |
|= |
Performs Bitwise OR on operands and assign value to left operand |
a|=b a=a|b |