Predict the Output: Assignment Aliasing
Beginner · Predict the output · from Python Copy vs Deepcopy: Why Your "Copy" Isn't Really a Copy
From the lesson: Python Copy vs Deepcopy: Why Your "Copy" Isn't Really a Copy
Imagine you have a folder full of photos. You make a copy of the folder and give it to a friend. But here's the catch - only the folder is new. The photos inside are the same physical photos, shared by both folders. If your friend draws a mustache on one, your photo has the mustache too.
Read the lessonRead the code carefully. What will it print? Remember that = with lists creates an alias, not a copy.
Type the exact output.
a = [10, 20, 30]
b = a
b[1] = 99
print(a)
print(a is b)
More Copy and Deepcopy exercises
- Make an Independent CopyBeginner
- Predict the Output: Shallow Copy TrapIntermediate
- Safe Copy of Nested DataIntermediate
- Fix the Game State BugAdvanced
All Python exercises · 50 practice problems · Data Structures quiz