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

Recommended Answers

All 4 Replies

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
commented: Helped a lot, answered question. +1

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.