+ 1
Two reference for list
x=[1,2,3] print(x[1]) y=x y[1]=10 print(x) print(y) 1,2,3 is the list of values which is stored in the memory x is a reference for that list so when we say x=y y is also referring to the same values by now when we change or modify any values . it will be highlighted in both variables
1 Resposta
0
You have to use list slicing.
x=[1,2,3]
print(x[1]) #output 2
y=x[:]
y[1]=10
print(x) # output [1, 2, 3]
print(y) # output [1, 10, 3]