Python Common list method sharing

Source: Internet
Author: User
This article mainly with you to share Python common list method, mainly in the form of code and we explain, hope to help everyone.

Append (...) add an element at the end of the list
| L.append (object), None--Append object to end

Count (...) checks if 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 (...) inserts an element before an element

| L.insert (Index, object)--Insert object before index

Pop (...) delete an element The default is the last Pop (0) is to delete the first element
| 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.

Sort (...) ordering requires the same element type, 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 (...) to delete an element of a value
| L.remove (value), None--Remove first occurrence of value.
| Raises valueerror if the value is not present.

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.