What is the output of the following Python code snippet?
import copy
a = [1, [2, 3]]
b = copy.copy(a)
b[1][1] = 99
print(a, b)
-
A
[1, [2, 3]] [1, [2, 99]]
-
B
[1, [2, 99]] [1, [2, 3]]
-
C
[1, [2, 99]] [1, [2, 99]]
Correct answer
-
D
Error
Correct answer
C. [1, [2, 99]] [1, [2, 99]]
6 views
Explanation
A shallow copy shares the inner list, so changing it affects both copies.
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ