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)
2.1m questions
2.1m answers
60 comments
57.0k users