Python List Methods
Every list method — signature, real examples, and the #1 gotcha (most methods return
None and mutate in place). Python 3.10+.
Add Elements
list.append
Appends a single item x to the end of the list, mutating it in place. Always returns None — it does not return the modified list.
list.extend
Extends the list by appending every element from an iterable, in order. Mutates in place and returns None; equivalent to `list += iterable`.
list.insert
Inserts item x before index i, shifting subsequent elements right. Mutates in place, returns None; O(n) because it shifts trailing elements.
Remove Elements
list.remove
Removes the first occurrence of a value equal to x from the list. Raises ValueError if x is not present; returns None.
list.pop
Removes and returns the item at position i (default -1, the last item). Raises IndexError on an empty list or an out-of-range index.
list.clear
Removes all items from the list in place. Equivalent to `del lst[:]`; returns None.
del list[...]
Statement that deletes the element or slice at the given position, mutating the list in place. Unlike pop() it does not return the removed value; unlike remove() it targets by index, not by value.
Access & Search
list.index
Returns the zero-based index of the first item equal to x within the optional [start, end) range. Raises ValueError if no match is found.
list[i] / list[i:j:k]
Subscript syntax to read a single element (by index) or a new list (by slice). Slicing always returns a new shallow copy; out-of-range slice bounds are silently clamped while single-index access raises IndexError.
Ordering
list.sort
Sorts the list in place using the stable Timsort algorithm; returns None. Elements must be pairwise comparable unless a key function reduces them to a comparable value.
list.reverse
Reverses the elements of the list in place. Returns None; O(n) time and O(1) extra space.
sorted (built-in)
Built-in function that returns a NEW sorted list from any iterable, leaving the source untouched. Uses the same stable Timsort and key/reverse arguments as list.sort.
Inspection
list.count
Returns the number of times x appears in the list. Comparison uses equality; returns 0 if x is not present (never raises).
x in list
Membership test operator that returns True if any element equals x, else False. Runs in O(n) — for repeated lookups, convert to a set (O(1) per test).
len (built-in)
Returns the number of elements in the list as an int. O(1) because CPython lists track their length internally.