+ 4
Is there any difference between a+=1 and a=a+1?(although i think it's the same I want to know if there's any exception )
13 Respuestas
+ 11
a+=1 is the exact same as a=a+1, and is used just a shorter way of writing it (I can't really think of any situation where you would need to use a=a+1 rather than a+=1, so I would just recommend sticking with the latter as writing the least amount of code is always your best option.
+ 5
Its the same!
+ 4
The difference is one character in the source code discounting white space.
+ 3
If incrementing by 1 just use ++ ... otherwise use += ... or varname = varname + num. Not sure if there's a difference in performance from one over another. Careful here too... note that using + can also concatenate strings. So be sure what you are incrementing is a number.
+ 1
thanks Faisal
+ 1
hi
no, both have same result.
+ 1
No
+ 1
As I know there is a little diference on CPU timming, independently of the language.
Check this code to comprobe:
https://code.sololearn.com/cH4Pt8zaFR3d/?ref=app
0
Nozoo
0
It is the same ~no difference.
0
a+=1 is exactly the same to a =a+1;
There is no program error as I think
0
No, a+=1 is the shortest form of a=a+1
- 2
Of course!