CurriculumPython Lists, Indexing and Slicing for KidsChanging a list

Python append() and remove(): Changing a List

append, remove — and the surprising truth about copying a list.

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

Changing a list

Lists can change AFTER you make them. append adds; remove takes away. Both change the list IN PLACE.

list.append(item) adds one item to the end.

hoard = ["gold", "gems"]
hoard.append("sword")
print(hoard)

Output

['gold', 'gems', 'sword']

list.remove(item) takes ONE matching item out, by its VALUE — not by counting a position.

hoard = ["gold", "gems", "sword"]
hoard.remove("gems")
print(hoard)

Output

['gold', 'sword']

Now the surprising part. treasury = hoard does NOT make a copy — it makes treasury just another name for the SAME list.

hoard = ["gold", "gems"]
treasury = hoard
treasury.append("sword")
print(hoard)

Output

['gold', 'gems', 'sword']

hoard shows the sword too, even though you only touched treasury — because hoard and treasury were never two separate lists. They're one list with two names.

hoard = ["gold", "gems"]
treasury = hoard
treasury.append("sword")
print(hoard)

This is only true for LISTS, because they're mutable. Numbers and text don't do this — but this is a genuinely important thing to know about lists specifically.

Check your understanding

hoard = ["gold"]. treasury = hoard. treasury.append("gems"). What does print(hoard) show?

hoard = ["gold"]
treasury = hoard
treasury.append("gems")
print(hoard)
  • ['gold', 'gems'] — hoard shows the change too
  • ['gold'] — hoard is unaffected, only treasury changed
  • This causes an error, because treasury was never really defined

Why: hoard shows 'gems' too — hoard and treasury were always the same list underneath, just with two different names pointing at it. Changing the list through EITHER name changes the one thing both names refer to.

What you'll practice

hoard = ["gold", "gems"]. A sword arrives. Use append to add "sword" to the end, then print the whole hoard.

Unlock this lesson with PRO →

More from this topic

Changing a list 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 →