0

I expect the code below to create x, then make a copy of x which i called y, change x and then output y. That is, I expect the lines of code to be run sequentially.

x = [10,20,30]
y = x
x[1] = 42
print(y)

Instead, y is changed when x is. Why is that, and how should I read the code? the output is:

[10, 42, 30] 
miradulo
  • 26,763
  • 6
  • 73
  • 90
Student tea
  • 117
  • 5

0 Answers0