is this what it means that x and y are the same object not just the values that they are basically connected ? or I'm getting the 'is' statement wrong
>>> x=[2,8]
>>> y=x
>>> x.reverse()
>>> y
[8, 2]
>>> y is x
True
is this what it means that x and y are the same object not just the values that they are basically connected ? or I'm getting the 'is' statement wrong
>>> x=[2,8]
>>> y=x
>>> x.reverse()
>>> y
[8, 2]
>>> y is x
True
You have it exactly right on all counts, they are the same object, and that is what is
is meant to show. =
does not make a copy. One way to copy the list is with y = list(x)
.
That's right, they are exactly the same object - they a sharing the same memory address. If you modify one, you modify them both, like so:
x = [2, 8]
y = x
x.reverse()
print(y) # [8, 2]
If you don't want this you can make a copy using y = x[:]
.