a = x
creates a reference:
a = [2]
x = a
print id(a)
print id(x)
Produces:
39727240
39727240
So if you alter a
then x
would change too because they are the same objects
Whereas
a = x[:]
creates a new object
a = [2]
x = a[:]
print id(a)
print id(x)
Produces:
41331528
39722056
But over here changing a
doesn't alter x
because they are different objects