0

I have a question about how changing values in copied(?) lists can affect the original one.

An Example:

a = [1, 2, [3,4]]
b = list(a)

b.append(100)
b 
[1,2,[3,4],100]
a 
[1,2,[3,4]] 

b[2][0] = -100
b 
[1,2,[-100,4],100] 
a
[1,2,[-100,4]] 

b[0] = 3
b 
[3,2,[-100,4],100] and
a
[1,2,[-100,4]]

Why sometimes changing or adding values on list(b) doesn't affect list(a) and sometimes it does affect list(a)?

slartidan
  • 20,403
  • 15
  • 83
  • 131
오정훈
  • 1
  • 1

0 Answers0