add
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.append(x) Parameters
| Parameter | Purpose |
|---|---|
| x | The single object to append; can be any type, including another list (nested). |
| (no keyword args) | append() takes exactly one positional argument — no options. |
Examples
>>> nums = [1, 2, 3]
>>> nums.append(4)
>>> nums
[1, 2, 3, 4] Basic append of a single int.
>>> lst = [1, 2]
>>> lst.append([3, 4])
>>> lst
[1, 2, [3, 4]] append adds the argument as ONE element — use extend to unpack an iterable.
>>> x = [].append(1)
>>> print(x)
None append returns None — never assign its result.
>>> lst = [1]
>>> lst.append('a')
>>> lst
[1, 'a'] Lists are heterogeneous — any type works.
Gotcha
append mutates in place and returns None. Writing `x = lst.append(1)` sets x to None. Also, append([1,2]) adds the list as a nested element — use extend for flattening.
Related methods
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.
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.
← All Python list methods · Dict methods · list vs tuple vs set