Himanshu SharmaSoftware engineer
Let’s talk

Python Tutorial · Lesson 26 of 70

Python list methods: append, remove, sort and more

Learn the everyday Python list methods, including append, insert, extend, remove, pop, index, count, sort and reverse, and what each one returns.

14 minCollectionsUpdated 14 November 2026

Awaiting technical review. This lesson is readable but not yet listed in search engines.

By the end of this lessonAdd, remove, find, count and reorder list items with the built-in list methods, and know which ones return None.

After this lesson you can grow, shrink, search and reorder a list using its built-in methods. A method is a function that belongs to an object, called with a dot: items.append(5). Lists come with a handful of them, and most programs use the same few over and over.

Adding items

We will keep a to-do list for a small shop. Start with a list and add to it:

python
tasks = ["open shop", "count cash"]
tasks.append("restock shelves")
print(tasks)
tasks.insert(1, "turn on lights")
print(tasks)
result
['open shop', 'count cash', 'restock shelves']
['open shop', 'turn on lights', 'count cash', 'restock shelves']

append always adds at the end. insert(position, item) places the item at the given index and shifts the others along. Adding at the end is quick; inserting near the front of a very large list is slower because everything after it has to move, though for normal-sized lists you will never notice.

To add several items at once, use extend with any collection:

python
tasks.extend(["clean floor", "close shop"])
print(tasks)
result
['open shop', 'turn on lights', 'count cash', 'restock shelves', 'clean floor', 'close shop']

Here is the trap with append: if you give it a list, the whole list becomes one item.

python
nested = [1, 2]
nested.append([3, 4])
print(nested)
print(len(nested))
flat = [1, 2]
flat.extend([3, 4])
print(flat)
result
[1, 2, [3, 4]]
3
[1, 2, 3, 4]

You can also join lists with +, which makes a new list, and repeat one with *:

python
print([1, 2] + [3])
print([0] * 4)
result
[1, 2, 3]
[0, 0, 0, 0]

Removing items

There are three common ways, and they differ in how you point at the item.

python
letters = ["a", "b", "c", "b", "d"]
letters.remove("b")
print(letters)
last = letters.pop()
print(last, letters)
first = letters.pop(0)
print(first, letters)
result
['a', 'c', 'b', 'd']
d ['a', 'c', 'b']
a ['c', 'b']

remove(value) deletes the first item equal to the value. pop() removes the last item, and pop(index) removes the one at that position. Both pop forms return the item, which is useful when you want to use it. The del statement also removes by position or slice, and clear() empties everything:

python
numbers = [10, 20, 30, 40, 50]
del numbers[0]
print(numbers)
del numbers[1:3]
print(numbers)
numbers.clear()
print(numbers)
result
[20, 30, 40, 50]
[20, 50]
[]

Removing something that is not there is an error:

python
["a", "b"].remove("z")
result
ValueError: list.remove(x): x not in list

If you are unsure, test first with if "z" in items:.

Finding and counting

index(value) tells you the position of the first match. count(value) tells you how many times a value appears.

python
votes = ["tea", "coffee", "tea", "juice", "tea"]
print(votes.index("coffee"))
print(votes.count("tea"))
print(votes.count("milk"))
result
1
3
0

Like remove, index raises a ValueError when the value is missing, while count happily returns 0.

Reordering

reverse() flips the list in place, and sort() puts the items in order:

python
ages = [31, 18, 45, 22]
ages.sort()
print(ages)
ages.reverse()
print(ages)
ages.sort(reverse=True)
print(ages)
result
[18, 22, 31, 45]
[45, 31, 22, 18]
[45, 31, 22, 18]

You will see a lot more about ordering in the sorting lesson, including sorting by a rule you choose.

Methods that return None

Notice that append, extend, insert, remove, sort, reverse and clear change the list and give nothing back. What they return is None. This leads to the most famous list bug:

python
data = [3, 1, 2]
data = data.sort()
print(data)
result
None

The list was sorted, then the name data was pointed at the None that sort returned, and the list was lost. Call the method on its own line and keep the name:

python
data = [3, 1, 2]
data.sort()
print(data)
print(sorted([3, 1, 2]))
result
[1, 2, 3]
[1, 2, 3]

sorted() is a function rather than a method. It leaves the original alone and returns a new list.

A small worked example

Putting several methods together, here is a queue of customers where the first to arrive is served first:

python
queue = []
queue.append("Asha")
queue.append("Ben")
queue.append("Chloe")
served = queue.pop(0)
print("Serving", served)
print("Waiting:", queue)
result
Serving Asha
Waiting: ['Ben', 'Chloe']

For a real queue with many items, Python has a better tool in the standard library, but a list is fine for small jobs.

Common mistakes

  • Writing items = items.sort() or items = items.append(x). These assign None. Call the method on its own.
  • Using append when you meant extend. You end up with a list inside a list.
  • Removing while looping. Calling remove inside a for loop over the same list skips items. Build a new list instead.
  • Expecting remove to delete every match. It removes only the first one.
  • Calling pop on an empty list. It raises an IndexError. Check if items: first.

Exercise

Start with cart = ["pen", "book"]. Add "bag" to the end, put "ruler" at the front, remove "book", then print the cart and its length.

Show one possible answer
python
cart = ["pen", "book"]
cart.append("bag")
cart.insert(0, "ruler")
cart.remove("book")
print(cart)
print(len(cart))
result
['ruler', 'pen', 'bag']
3

Previous: Lists. Next: Tuples, a collection that cannot be changed.

Key points

  • append adds one item at the end, extend adds every item of another collection, and insert adds at a chosen position.
  • remove deletes the first item with a given value, pop deletes by position and hands the item back, and clear empties the list.
  • index finds a position and count counts matches. index raises ValueError when the value is missing.
  • Methods that change a list in place, such as append, sort and reverse, return None. Do not write items = items.sort().

Check yourself

1. What is the difference between append and extend?
2. What does names.pop() do with no argument?
3. After result = [3, 1, 2].sort(), what is result?
4. What happens when you call remove with a value that is not in the list?