Python List Methods Reference

Every Python list method with signature, return value and in-place flag

Searchable reference for all Python list methods — append, extend, insert, remove, pop, sort, reverse — showing each method's signature, return value, and whether it mutates the list in place. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

Why does list.sort() return None?

list.sort() sorts the list in place and deliberately returns None to signal that it mutated the object rather than producing a new one. This is a Python convention for in-place methods. A common bug is writing items = items.sort(), which assigns None; to get a sorted copy use sorted(items), which returns a new list and leaves the original unchanged.

Python’s list is a mutable sequence with a small, fixed set of methods. The key thing to know is which ones mutate in place (and return None) versus which ones return a value. This is a searchable offline reference.

Complete method table

MethodSignatureReturnsMutates?
appendappend(x)NoneYes
extendextend(iterable)NoneYes
insertinsert(i, x)NoneYes
removeremove(x)NoneYes
poppop(index=-1)removed elementYes
clearclear()NoneYes
sortsort(*, key=None, reverse=False)NoneYes
reversereverse()NoneYes
indexindex(x, start, end)int positionNo
countcount(x)int tallyNo
copycopy()new listNo

In-place vs returns-a-value: the core distinction

  • In-place, returns Noneappend, extend, insert, remove, sort, reverse, clear. These change the list itself; assigning their result (x = x.sort()) is a classic bug that stores None.
  • Returns a valuepop returns the removed element, index returns a position, count returns a tally, copy returns a new list.

The single most common mistake is items = items.sort(). Use items.sort() to sort in place, or sorted(items) for a new sorted list.

append vs extend

a = [1, 2]
a.append([3, 4])   # a -> [1, 2, [3, 4]]   (one nested element)

b = [1, 2]
b.extend([3, 4])   # b -> [1, 2, 3, 4]      (concatenated)

remove vs pop

remove(value) deletes the first occurrence of a value by equality — it raises ValueError if the value is absent. pop(index) deletes and returns the element at a given index, defaulting to the last element.

items = [10, 20, 30, 20]
items.remove(20)   # items -> [10, 30, 20]  (first 20 removed, no return value)

val = items.pop(0)  # val = 10, items -> [30, 20]

Sorting: key and reverse

list.sort() sorts in place using the natural ordering. Use key to sort by a derived value, and reverse=True for descending order:

words = ["banana", "apple", "cherry"]
words.sort(key=len)         # -> ['apple', 'banana', 'cherry']  (by length)
words.sort(reverse=True)    # -> ['cherry', 'banana', 'apple']

sorted(items) does the same but returns a new list and leaves the original unchanged.

Notes

  • pop(0) removes the first element but is O(n) — prefer collections.deque for FIFO queues.
  • copy() is a shallow copy — nested mutable objects are shared between original and copy; use copy.deepcopy for a fully independent clone.
  • len, sorted, reversed, min, max are built-in functions, not list methods.
  • list.sort() is guaranteed stable in Python 3 — equal elements keep their original relative order.