Editor

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 documents. You photocopy the folder and give it to a friend. But here's the catch - the photos inside the folder aren't copies. They're the same physical photos. If your friend draws a mustache on one, your original photo is ruined too.

Read the lesson

Read 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 vs Deepcopy exercises

All Python exercises · 50 practice problems · Data Structures quiz