Here they are -= and +=. What do they mean?

4
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by Ene Uran

Here is the spiel:

``````a += b  Roughly equivalent to a = a + b
a -= b  Roughly equivalent to a = a - b
a *= b  Roughly equivalent to a = a * b
a /= b  Roughly equivalent to a = a / b
a //= b  Roughly equivalent to a = a // b
a %= b  Roughly equivalent to a = a % b
a **= b  Roughly equivalent to a = a ** b
a &= b  Roughly equivalent to a = a & b
a |= b  Roughly equivalent to a = a | b
a ^= b  Roughly equivalent to a = a ^ b
a >>= b  Roughly equivalent to a = a >> b
a <<= b  Roughly equivalent to a = a << b``````

Thanks Sneekula, I got it now!

Here is the spiel:

``````a += b  Roughly equivalent to a = a + b
a -= b  Roughly equivalent to a = a - b
a *= b  Roughly equivalent to a = a * b
a /= b  Roughly equivalent to a = a / b
a //= b  Roughly equivalent to a = a // b
a %= b  Roughly equivalent to a = a % b
a **= b  Roughly equivalent to a = a ** b
a &= b  Roughly equivalent to a = a & b
a |= b  Roughly equivalent to a = a | b
a ^= b  Roughly equivalent to a = a ^ b
a >>= b  Roughly equivalent to a = a >> b
a <<= b  Roughly equivalent to a = a << b``````

What do you mean "Roughly equivalent"? `a += b` is the exact same thing as `a = a + b` .

Just like in C, a += b does the same thing as a = a + b, but the code produced is more efficient. So, I think, the roughly is there for the sticklers in life.