Python Data Science Jobs & Interviews
18.4K subscribers
146 photos
3 videos
17 files
258 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
加入频道
Question 22 (Interview-Level):
Explain the difference between deepcopy and regular assignment (=) in Python with a practical example. Then modify the example to show how deepcopy solves the problem.

import copy

# Original Problem
original = [[1, 2], [3, 4]]
shallow_copy = original.copy()
shallow_copy[0][0] = 99
print(original) # What happens here?

# Solution with deepcopy
deep_copied = copy.deepcopy(original)
deep_copied[1][0] = 77
print(original) # What happens now?


Options:
A) Both modify the original list
B) copy() creates fully independent copies
C) Shallow copy affects nested objects, deepcopy doesn't
D) deepcopy is slower but creates true copies

#Python #Interview #DeepCopy #MemoryManagement

By: https://yangx.top/DataScienceQ
2