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.

Lesson 5 of 5PROAges 10+
See what PRO unlocks →

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 False

Now 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

None

The 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)
  • None
  • ['a', 'b'] — sorted correctly
  • ['b', 'a'] — unsorted, because sort failed

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)
  • No — hoard still just says ['gold']
  • Yes — hoard becomes ['gold', 'gems'] too, same as with plain =

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.

Unlock this lesson with PRO →

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 →