0
    a = [1,[2,3]]
    b = a[:]
    a[1][1] = 5
    print(b)

#outputs [1,[2,5]]

Why is b[1][1] getting reassigned?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • 1
    `copy()` only works on the first layer; to copy nested mutable objects you need `deepcopy` from the `copy` module – ddejohn Aug 28 '21 at 22:01
  • 2
    Does this answer your question? [What is the difference between shallow copy, deepcopy and normal assignment operation?](https://stackoverflow.com/questions/17246693/what-is-the-difference-between-shallow-copy-deepcopy-and-normal-assignment-oper) – ddejohn Aug 28 '21 at 22:02
  • Yes,that pretty much answers it.Thank you very much, @blorgon – AungMinKhant Aug 28 '21 at 22:11

0 Answers0