0

I'm a novice at python, and I've just started to learn about lists. I have tried to make a copy of different kind of lists and then changing the copy. The last case actually changes the list of the original when changing the copy. I really can't understand why this is happening:

a=[1,2,3,4]
c=a[:]
c[2]=100
print("a=", a)

Which gives me a= [1,2,3,4]

a = [[1, 2], [3, 4]]
c=a[:]
c[1]=[3,100]
print("a=", a)

which gives me a=[[1,2],[3,4]]

a = [[1, 2], [3, 4]]
c=a[:]
c[1][1]=100 
print("a=", a)

Which changes a, and gives me a=[[1,2],[3,100]].

Can anyone explain to me, why a is changed when changing the copy of a in the last case?

0 Answers0