Home  >  Article  >  Backend Development  >  Sharing of commonly used list methods in Python

Sharing of commonly used list methods in Python

小云云
小云云Original
2018-03-30 17:09:001486browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn