#10 most askedVery commonMediumData types & mutability
Shallow copy vs deep copy
๐ข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.What's the difference between copy.copy and copy.deepcopy? Predict the output.
๐ฎ Predict the output
import copy
a = [[1, 2], [3]]
shallow = a[:]
deep = copy.deepcopy(a)
a[0].append(99)
grid = [[0] * 2] * 2
grid[0][0] = 5
print(shallow[0], deep[0], grid)
๐ค Answer it out loud, then check yourself
Say your answer as if the interviewer is listening (30โ90 seconds). Then reveal what a strong answer covers and tick what you said.
Answer out loud first, then compare.
Want to rehearse it?Answer this to the AI interviewer and get a verdict โ