- 1
What is the different between in-place operator and variables in python
2 Respuestas
+ 3
You are comparing two completely different things here:
In-place operator is also about variables. It's just another way to change the value of a variable.
x = x + 2
Here we create a new value from x + 2 and then give it the name x. (The old x is lost now.)
x += 2
Here we change x directly.
+ 2
variables are identifiers used to refer to some memory emplacement...
in-place operators are shortcut to assign result of operation between at least one variable and some expression (with or without variable)...
my_var = 36 # simple assignement
my_var += 6 # same as my_var = my_var+6