Earlier in the chapter, you learned about the assignment operator, =. Now, we will see some more variants of the assignment operator, often used in combination with arithmetic operators:
Operator |
Description |
= |
x=y , y is assigned to x |
+= |
x+=y is equivalent to x=x+y |
-= |
x-=y is equivalent to x=x-y |
*= |
x*=y is equivalent to x=x*y |
/= |
x/=y is equivalent to x=x/y |
**= |
x**=y is equivalent to x=x**y |
Here, we will look at a few examples of the variants of the assignment operator: