It was difficult to understand the difference between the following two lines (why do you put a slice on the left side), so a memorandum.
y[:] = x
y = x
As shown below, when y [:] = x
, the id of y does not change, but when y = x
, the id of y becomes that of x.
>>> x = [1,2,3]
>>> y = [4,5,6]
>>> id(x)
4481009352
>>> id(y)
4481133744
>>> y[:] = x
>>> y
[1, 2, 3]
>>> id(y)
4481133744
>>> y = x
>>> y
[1, 2, 3]
>>> id(y)
4481009352
I'm blogging: Weed software
Recommended Posts