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👍👍👍😃
4 odpowiedzi
+ 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.
+ 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.
+ 1
Thanks very much, appriciate that!!
0
Rik no problem :)