1

I thought that if:

from copy import deepcopy

list1 = ['a', 'b', 'c']
list2 = deepcopy(list1)

then the id's must be like id(list1) != id(list2) and id(list1[0]) != id(list2[0]), but actually it behaves like:

id(list1) != id(list2)

yet

id(list1[0]) == id(list2[0])

Could anyone can explain this unusual behavior?

jnooree
  • 55
  • 4
  • 2
    strings are immutable - no copying of the object is needed - just incrementing the reference count to the string itself... Try it with a mutable type and that will be copied... – Jon Clements Nov 22 '17 at 12:59

0 Answers0