Why use copy.deepcopy() instead of copy.copy() for a list of lists?
A
To copy the list faster using less memory
B
To remove duplicate items while copying
C
To convert the list into an immutable tuple
D
To copy the inner lists as well
Correct answer
Correct answer
D. To copy the inner lists as well
19 views
⚔️
Challenge a friend on Python
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
A shallow copy creates a new outer list that still points to the same inner lists, so editing one affects both. deepcopy recursively copies every nested object.
Reference
Asked in: NTS, Python Developer Interviews
Doubts & discussionNot sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ What is the result of list(zip([1, 2, 3], ['a', 'b']))? Next MCQ › What does the 'walrus operator' (:=), added in Python 3.8, do?