How can `id()` prove whether `L = L + L` built a new list while `L.clear()` changed the same one in place?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The concatenation operator + joins two lists into a brand-new list. Starting from values = [1, 2, 3, 4], build a new list that is values followed by a second copy of itself, and assign it to doubled. Concatenation returns a new object — it must not change values.
L = L + L inside a loop over the elements
Trace L = [1, 2, 3, 4] through four passes of L = L + L, writing the doubled list printed each time and recording that the loop stops after the fourth pass.
The loop variable bound to the abandoned object
Draw the diagram showing e still walking the original four-element object once L names the doubled one, and write the rule separating an object in memory from its name.
L.clear() against L = [] under id
Record the console run where id(L) is unchanged across L.append(8) and L.clear(), then differs once L = [] binds a fresh empty list and drops the old one.