Why | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why

Why remove the variables x=x+3 to x +=3 Wont this cause problems later?

14th Sep 2018, 5:58 AM
John Adair
John Adair - avatar
7 Answers
+ 7
x += 3 is just a short form of x = x + 3. It's up to you which one would you prefer.
14th Sep 2018, 6:12 AM
Email Not Activated
+ 5
John Adair No it doesn't assume the answer is the same with variable. This form: x += 3 means the current value of x will be added by 3 and the answer will be the NEW value of x.
14th Sep 2018, 6:15 AM
Email Not Activated
+ 2
And what problems would it cause. x=x+3 is equivalent to x+=3.
14th Sep 2018, 6:01 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
x=x+3 and x+=3 both are one and the same...none of them will cause problem Its on u what u use... except x+=3 looks good and its shorter( *-*just one character shorter)
14th Sep 2018, 6:05 AM
Rohit Singh
Rohit Singh - avatar
0
it assumes the answer and the variable are the same
14th Sep 2018, 6:02 AM
John Adair
John Adair - avatar
0
i finish the module one and it is saying 12/13 and wont let me move on. -_-
14th Sep 2018, 6:14 AM
John Adair
John Adair - avatar
0
x+=3 works and is widely used in most, if not all modern programming languages and with all operators (-=, /= etc.). It's just a compact way to write x=x+3 or x+3=x in order to save you some typing. If you don't like it, you don't have to use it. But you should definitely know what it means.
14th Sep 2018, 6:21 AM
Anna
Anna - avatar