Python List Method

Source: Internet
Author: User

Python List Method


Def append (self, p_object) # append to the end of the list

Def clear (self): # delete all elements in the list

Def copy (self) # list copying

Def count (self, value) # returns the number of times a list element appears.

Def extend (self, iterable) # Same as for loop, can be iterated.
Example:
Li = ['A', 'B', 'C', 'D'] l = ['E', 'F'] li. extend (l) print (li) ['A', 'B', 'C', 'D', 'E', 'F'] # return results

Def index (self, value, start = None, stop = None) # Return the index location of the corresponding value through the value parameter.

Def insert (self, index, p_object) # insert an element at a specified position

Example:
Li. insert (2, 'Hello') # indicates that the value 'Hello' is inserted after 2nd elements'
        

Def pop (self, index = None) # It is deleted by default. If no element in the list is displayed, an error is returned.

Def remove (self, value) # When multiple identical values appear in the list, delete the first

L. remove (value)-> None -- remove first occurrence of value.


Def reverse (self) # reverse the list element
"L. reverse () -- reverse * in place *"""


Def sort (self, key = None, reverse = False) # sort
      """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
 

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.