← Quiz: References and Copying: all 10 questions
Quiz: References and Copying · Question 3 of 10
What does this print? (code)
What does this print?
import copy
a = [[1], [2]]
b = copy.copy(a)
b[0].append(9)
print(a)
- A.[[1], [2]]
- B.[[1, 9], [2], 9]
- C.[[1], [2], [9]]
- D.[[1, 9], [2]]
Answer & explanation
Correct answer: [[1, 9], [2]]
A shallow copy shares the inner lists, so changing b[0] also changes a[0].
Can you get the rest right without peeking?
Take the timed Quiz: References and Copying quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →