Python 3 reference · 11 entries

Python List Methods

Every Python list method, from append() to sort(), with syntax, parameters and examples you can run. Most of them change the list in place and return None.

List methods such as append(), sort() and reverse() change the list in place and return None.

NameDescriptionSince
list.append() Add one item to the end of a list, changing the list in place. Returns None. 3.0
list.clear() Remove every item from the list in place, leaving an empty list. Other references see the change too. 3.0
list.copy() Return a shallow copy of the list: a new list with the same items. Nested objects are still shared. 3.0
list.count() Return how many times a value appears in the list, comparing each item with ==. Returns 0 if it never appears. 3.0
list.extend() Add every item from an iterable to the end of the list, in place. Like append() for many items at once. 3.0
list.index() Return the position of the first item equal to a value. Raises ValueError if the value isn't in the list. 3.0
list.insert() Insert an item at a given position, shifting later items to the right. Index 0 adds to the front. 3.0
list.pop() Remove and return the item at a position, the last item by default. Raises IndexError on an empty list. 3.0
list.remove() Remove the first item equal to a value. Raises ValueError if the value is not in the list. 3.0
list.reverse() Reverse the order of the items in place. Returns None; use reversed() or slicing for a reversed copy. 3.0
list.sort() Sort the list in place, optionally by a key function and in reverse. Returns None; sorted() returns a new list. 3.0