Question #131

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

When copy.copy() is used (shallow copy), the copy of the object has a new memory address but its elements refer to the elements of the copied object. Here, a[0] and b[0] are the same object with the same memory address. (

Comment on Disqus:

Comment on Twitter:

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

Similar questions: