List Methods in Python
append()
The append() method in Python is used to add a single element to the end of a list, modifying the list in place.
clear()
The clear() method in Python is used to remove all elements from a list, making it an empty list.
copy()
The copy() method in Python is used to create a shallow copy of a list, returning a new list with the same elements as the original list.
count()
The count(element) method in Python is used to count the number of occurrences of a specified element in a list and returns the count.
extend()
The extend(iterable) method in Python is used to append elements from an iterable (e.g., another list) to the end of an existing list, modifying the list in place.
index()
The index(element, start, end) method in Python is used to find the lowest index of a specified element within a given list, optionally within a specified range, and it returns the index of the first occurrence or raises a ValueError if the element is not found.
insert()
The insert(index, element) method in Python is used to insert a specified element at a given index in a list, shifting existing elements to accommodate the insertion, and it modifies the list in place.
pop()
The pop(index=-1) method in Python is used to remove and return the element at a specified index (default is the last element) from a list, modifying the list in place.
remove()
The remove(element) method in Python is used to remove the first occurrence of a specified element from a list, modifying the list in place, and it raises a ValueError if the element is not present.
reverse()
The reverse() method in Python is used to reverse the order of elements in a list, modifying the list in place.
sort()
The sort(key=None, reverse=False) method in Python is used to sort the elements of a list in ascending order by default or in descending order if reverse is set to True, and it modifies the list in place.