+ 1

Don't understand why you would want to write x=x+3 as x=+3?

for some reason I can't wrap my head around the logic, will appreciate it if someone will explain to me, thanks!

7th Oct 2017, 11:39 PM
Adebisi Adetunji
Adebisi Adetunji - avatar
6 Answers
+ 4
x+=3 is a shortcut way for x=x+3
7th Oct 2017, 11:45 PM
Mohammed Hany
Mohammed Hany - avatar
+ 1
Thanks guys!
8th Oct 2017, 12:00 AM
Adebisi Adetunji
Adebisi Adetunji - avatar
+ 1
It's a lot clearer to me
8th Oct 2017, 12:02 AM
Adebisi Adetunji
Adebisi Adetunji - avatar
0
It's simply a shortcut, and it doesn't affect readability, and because people want to be more efficient, people do +=, -=, *=, /=, etc. There is nothing wrong with doing x = x + 3.
7th Oct 2017, 11:55 PM
LunarCoffee
LunarCoffee - avatar
0
The longer the left hand side is, the more useful this shorthand is, also if you are assigning to an array/list/dict element, the index/key is calculated once instead of twice
9th Oct 2017, 8:25 PM
Amr Ibrahim Khudair
Amr Ibrahim Khudair - avatar