There are lots of times in programming when we have to assign values to various variables. In Python, there are different assignment operators for doing these kinds of tasks. You can use two types of assignment operators in Python: simple assignment operators like
=, and compound assignment operators like
This tutorial will tell what the
-= assignment operator is in Python.
-= Operator in Python
-= operator is a decremental assignment operator in Python. It subtracts the operand on the right side from the operator on the left side and finally assigns the resultant difference to the operand on the left side.
So, we can say that
c -= 10 is similar to
c = c - 10.
Now let us see how we can use the
-= operator in Python.
x = 10 y = 5 x -= y print(x)
x -= y statement means
x = x - y i.e.,
x = 10 - 5, which is equal to
Just like the
-= operator, there are many different types of compound assignment operators like
|= that help in carrying out all the basic kinds of arithmetic operations, boolean operations, and others.