← Back to Blog

List Methods That Change the List

The problem...

You have a list. But it's not final.

You need to add something. Remove something. Sort it. Flip it around.

Lists in Python aren't frozen — you can change them after you create them.

That's what mutable means. And there are methods built specifically for it.

The idea!

Python gives you a set of methods that modify the list directly.

No new list is created. The original changes.

That's the key difference from slicing or indexing — those read. These write.

Adding elements

append() adds one element to the end:

squad = ["Raven", "Wolf"]
squad.append("Ghost")
print(squad)

Output → ['Raven', 'Wolf', 'Ghost']

insert() adds one element at a specific position:

squad = ["Raven", "Wolf", "Ghost"]
squad.insert(1, "Viper")
print(squad)

Output → ['Raven', 'Viper', 'Wolf', 'Ghost']

First argument: the index. Second argument: the value. Everything else shifts right.

extend() adds all elements from another list:

squad = ["Raven", "Wolf"]
reinforcements = ["Ghost", "Viper"]
squad.extend(reinforcements)
print(squad)

Output → ['Raven', 'Wolf', 'Ghost', 'Viper']

Removing elements

remove() removes the first element that matches the value:

squad = ["Raven", "Wolf", "Ghost", "Wolf"]
squad.remove("Wolf")
print(squad)

Output → ['Raven', 'Ghost', 'Wolf']

Only the first match is removed. If the value doesn't exist, Python raises a ValueError.

pop() removes and returns an element by index:

squad = ["Raven", "Wolf", "Ghost", "Viper", "Bull"]
last = squad.pop()
print(last)
print(squad)

Output:

Bull
['Raven', 'Wolf', 'Ghost', 'Viper']

No argument — removes the last element. Pass an index to remove from a specific position:

squad.pop(1)    # removes 'Wolf'

clear() removes everything:

squad = ["Raven", "Wolf", "Ghost"]
squad.clear()
print(squad)

Output → []

The list still exists. It's just empty now.

Sorting and reversing

sort() sorts the list in place — alphabetically for strings, numerically for numbers:

scores = [74, 98, 51, 85, 63]
scores.sort()
print(scores)

Output → [51, 63, 74, 85, 98]

To sort in descending order, pass reverse=True:

scores.sort(reverse=True)
print(scores)

Output → [98, 85, 74, 63, 51]

reverse() flips the list — no sorting, just reversal:

squad = ["Raven", "Wolf", "Ghost", "Viper", "Bull"]
squad.reverse()
print(squad)

Output → ['Bull', 'Viper', 'Ghost', 'Wolf', 'Raven']

What's really happening

All of these methods modify the list directly. There is no return value to capture — except for pop(), which returns the element it removed.

If you write squad = squad.append("Ghost"), you'll overwrite your list with None. Don't do that.

Heads up!

  • append() adds one element — extend() adds many
  • remove() needs the value — pop() needs the index
  • remove() raises ValueError if the value isn't in the list
  • pop() raises IndexError if the index doesn't exist
  • sort() and reverse() return None — they change the list, not create a new one
  • Don't mix types in a list you plan to sort — Python can't compare strings and integers

The mindset shift

Stop thinking: "My list is set once I create it."

Start thinking: "My list is a living structure. I control what goes in, what comes out, and what order it's in."

What you should understand now

  • append() adds to the end, insert() adds at a position, extend() adds a whole list
  • remove() deletes by value, pop() deletes by index and returns the element
  • clear() empties the list without deleting it
  • sort() sorts in place, reverse() flips in place
  • These methods modify the original list — they don't return a new one
[ login to bookmark ] // copied! 19 views · 2 min
// resources
Code Example list_methods_mutating.py
← prev Getting Elements Out of a List next → How to Inspect a List
// 0 comments
// No comments yet. Be the first.
// leave a comment

// Your comment will appear after approval.