When you do y = x, they are alias to the same objects in Python.
y = x
Try this if you don't want x to be changes when y changes:
x
y
x = [1, 2, 3, 4] y = x.copy() for i in range(0, len(x)): y[i] = x[i]**2 print(x) print(y)
1.4m articles
1.4m replys
5 comments
57.0k users