Question #132

What is the output of the code snippet below?
import copy
a = [1, 2]
b = copy.deepcopy(a)
print(a[0] is b[0])

When copy.deepcopy() is used, the copy of the object has a new memory address and its elements have new memory addresses too. However, the elements of a here are not mutable and as such copy.deepcopy() returns a shallow copy (behaves like copy.copy() ). (

Comment on Disqus:

Comment on Twitter:

Question difficulty: πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅

Similar questions: