Common methods of Python list

Source: Internet
Author: User

| Append (...)
| L.append (object)--Append object to end
|
| Count (...)
| L.count (value), integer--return number of occurrences of value
|
| Extend (...)
| L.extend (iterable)--extend list by appending elements from the iterable
|
| Index (...)
| L.index (value, [Start, [stop]]), integer-return first index of value.
| Raises valueerror if the value is not present.
|
| Insert (...)
| L.insert (Index, object)--Insert object before index
|
| Pop (...)
| L.pop ([index]), item-Remove and return item at index (default last).
| Raises indexerror If list is an empty or index is out of range.
|
| Remove (...)
| L.remove (value)--Remove first occurrence of value.
| Raises valueerror if the value is not present.
|
| Reverse (...)
| L.reverse ()--Reverse *in place*
|
| Sort (...)
| L.sort (Cmp=none, Key=none, Reverse=false)-stable sort *in place*;
| CMP (x, y)-1, 0, 1

It is important to note that:

Append () appends only one element, extend () can append an array;

Pop () deletes the element according to the subscript and returns the delete value; remove () is deleted by value and only the first one is deleted.

Common methods of Python list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.