Home > Article > Backend Development > Sharing of commonly used list methods in Python
This article mainly shares with you the commonly used list methods in Python. It is mainly explained to you in the form of code. I hope it can help you.
append(...) Add an element to the end of the list
| L.append(object) -> None -- append object to end
count(...) Check Whether the content exists in the list element
| L.count(value) -> integer -- return number of occurrences of value
extend(...) Merge list
| L.extend(iterable) -> None -- extend list by appending elements from the iterable
insert(...) Insert an element before an element
| L.insert(index, object) -- insert object before index
pop(...) When deleting an element, the default is the last one. pop(0) means deleting the first one. elements
| L.pop([index]) -> item -- remove and return item at index (default last).
| Raises IndexError if list is empty or index is out of range.
sort(...) Sorting requires the element types to be consistent, otherwise an error will occur!
| L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*
reverse(...) reverse order
| L.reverse() -- reverse *IN PLACE*
| remove(...) Remove elements of a certain value
| L.remove(value) -> ; None -- remove first occurrence of value.
|
The above is the detailed content of Sharing of commonly used list methods in Python. For more information, please follow other related articles on the PHP Chinese website!