Why put a slice on the left side in the substitution formula

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

Why put a slice on the left side in the substitution formula
Implement Sign In With Google on the backend side
Write a log-scale histogram on the x-axis in python
In matplotlib, set the vertical axis on the left side of the histogram to frequency and the vertical axis on the right side to relative frequency (maybe a wicked way)
A note on the default behavior of collate_fn in PyTorch
Put the lists together in pandas to make a DataFrame
Build a Selenium environment on Amazon Linux 2 in the shortest time
Anyway, the fastest serial communication log is left in a file
Find the rank of a matrix in the XOR world (rank of a matrix on F2)
Get the formula in an excel file as a string in Python
Get the number of readers of a treatise on Mendeley in Python
Put the module in the Pepper app
Enclose the cat result in double quotes and put it in a variable