0

I am trying to test the in-place addition claim of += in python, this is my code:

>>> a=1
>>> id(a)
4346593520
>>> a+=1
>>> id(a)
4346593552

As you can see, the addresses are different, but could it be due to the fact that 4346593552 holds the value 2 already?

Because, when I am assigning same values to two different variable, their addresses turn out to be the same. i.e.

>>> b=13
>>> c=13
>>> id(b)==id(c)
True

Please clarify if I am correct in my assumption, otherwise the in-place addition looks skeptical to me

zerotarun
  • 7
  • 2

1 Answers1

-1

+= Addition Assignment Description Adds a value and the variable and assigns the result to that variable.

Syntax A += B

A Any valid object. B Any valid object. Return Value According to coercion rules.

Remarks Equivalent to A = A + B. enter image description here

Asad
  • 1
  • 2