Here are some common list methods in Python:
-
append(): Adds an item to the end of the list.
my_list.append(item) -
extend(): Extends the list by appending elements from another iterable.
my_list.extend(iterable) -
insert(): Inserts an item at a specified position.
my_list.insert(index, item) -
remove(): Removes the first occurrence of a specified item.
my_list.remove(item) -
pop(): Removes and returns an item at a specified position (default is the last item).
item = my_list.pop(index) -
index(): Returns the index of the first occurrence of a specified item.
index = my_list.index(item) -
count(): Returns the number of occurrences of a specified item.
count = my_list.count(item) -
sort(): Sorts the items of the list in place.
my_list.sort() -
reverse(): Reverses the elements of the list in place.
my_list.reverse() -
copy(): Returns a shallow copy of the list.
new_list = my_list.copy()
These methods provide various functionalities to manipulate lists effectively.
