Feb-28-2018, 05:13 PM
>>> x = [1,2,3] >>> y = x >>> z = x[::] >>> x [1, 2, 3] >>> y [1, 2, 3] >>> z [1, 2, 3] >>> x[0] = 4 >>> x [4, 2, 3] >>> y [4, 2, 3] >>> z [1, 2, 3] >>> id(x) 140222264135304 >>> id(y) 140222264135304 >>> id(z) 140222264168648in your example y = x does not create new list, y reference the same object as x. In my example you can see they have the same id (i.e. they are the same object). I showed one of the possible methods to copy/clone a list. There are also other options see https://stackoverflow.com/a/2612815/4046632