CurriculumPython Lists, Indexing and Slicing for KidsReal copies, and the None trap
Why Copying a Python List with = Doesn't Actually Copy It
.copy() and [:] make a genuine second list — and why hoard = hoard.sort() empties it.
Real copies, and the None trap
You know treasury = hoard shares ONE list. Here's how to actually get a second, independent one.
hoard.copy() builds a brand new list with the same items — mutating the copy never touches the original.
hoard = ["gold", "gems"]
treasury = hoard.copy()
treasury.append("sword")
print(hoard)Output
['gold', 'gems']hoard[:] — a slice with nothing on either side of the colon — does the exact same thing. Both are real copies.
hoard = ["gold", "gems"]
treasury = hoard[:]
print(treasury == hoard, treasury is hoard)Output
True FalseNow a completely different trap. Some list methods change the list AND hand you back nothing.
hoard.sort() sorts hoard in place — and returns None. Assigning that None back to hoard destroys it.
hoard = ["gems", "gold"]
hoard = hoard.sort()
print(hoard)Output
NoneThe fix: call .sort() on its own line, with nothing capturing its result. hoard is already sorted — no reassignment needed.
hoard = ["gems", "gold"]
hoard.sort()
print(hoard)Output
['gems', 'gold'].append(), .reverse(), and .sort() all work this way: they mutate and return None. Never write x = x.append(...) either.
Check your understanding
hoard = ["b", "a"]. hoard = hoard.sort(). What does print(hoard) show?
hoard = ["b", "a"]
hoard = hoard.sort()
print(hoard)Why: .sort() genuinely sorts the list in place, but its RETURN VALUE is None — that's true of append() and reverse() too. hoard = hoard.sort() takes the correctly-sorted list and immediately overwrites it with None. The fix is just hoard.sort() on its own, no assignment.
hoard = ["gold"]. treasury = hoard.copy(). treasury.append("gems"). Does hoard change?
hoard = ["gold"]
treasury = hoard.copy()
treasury.append("gems")
print(hoard)Why: .copy() (and hoard[:]) are the actual fix for s3's aliasing surprise: they build a second, independent list, so treasury and hoard no longer point at the same thing.
What you'll practice
hoard = ["gold", "gems"]. This time, make treasury an ACTUAL COPY with hoard.copy() — not treasury = hoard. Then treasury.append("sword") and print(hoard). It should NOT have the sword.
More from this topic
Real copies, and the None trap is one lesson inside Python Lists, Indexing and Slicing for Kids — see the full lesson order and what the whole topic covers.
View the full topic →