Python list methods
Python List Methods
The Python list class includes the following methods, which you can use to add, update, and delete list items:
Sequence Number | Method and Description |
---|---|
1 | list.append(obj) Appends object obj to the end of the list |
2 | list.clear() Clears the list contents. |
3 | list.copy() Returns a copy of the list object. |
4 | list.count(obj) Returns the number of times obj appears in the list. |
5 | list.extend(seq) Appends the contents of seq to a list |
6 | list.index(obj) Returns the lowest index of the first occurrence of obj in the list |
7 | list.insert(index, obj) Inserts object obj into the list at offset index. |
8 | list.pop(obj=list[-1]) Removes and returns the last object or obj from the list. |
9 | list.remove(obj) Removes object obj from the list. |
10 | list.reverse() Reverses the objects in a list in place. |
11 | list.sort([func]) Sorts the objects in a list, using a comparison function if given. |