X = x + n | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

X = x + n

Hi am try to understand two concepts since I am new to Python and programming. First a have since that a variable ‘x’ is given a value but then the same variable is used to do another calculation e.g x = 3 and then x = x + 3 why would we give it another variable name? And second what is the concept of the In-place operator? E.g x+=5? Thanks for the hel👍👍👍😃

22nd Mar 2020, 11:39 AM
Richard Minamore
Richard Minamore - avatar
4 Answers
+ 2
x = x + 1 can be written in another way like x += 1. x = x * 5 can be written as x *= 5 Just a short form but does the same task.
22nd Mar 2020, 12:04 PM
maf
maf - avatar
+ 1
When u use =, u are assigning a value to a variable. x = 10 Now x is 10. If u now say, x = x + 5 Now x is 15, because 10 + 5. x = x * 2 Now x is 30, because 15 * 2.
22nd Mar 2020, 12:03 PM
maf
maf - avatar
+ 1
Thanks very much, appriciate that!!
22nd Mar 2020, 10:26 PM
Richard Minamore
Richard Minamore - avatar
0
Rik no problem :)
23rd Mar 2020, 6:36 AM
maf
maf - avatar