Python--List class

Source: Internet
Author: User


Python List Class Common methods


Class List (object):

def append (self, p_object): # Add elements to the list;

>>> name_list

[' shuoming ', ' python ', ' search ']

>>> name_list.append ("Python")

>>> name_list

[' shuoming ', ' python ', ' search ', ' python ']

def clear (self): # Clears all elements of the list, clears the list to an empty list;

>>> test_list

[' shuoming ', ' python ', ' search ', ' python ', ' automatic ', 1, 2]

>>> Test_list.clear ()

>>> test_list

[]

>>>


def copy (self):


def count (self, value): # Specifies the number of elements in the list;

>>> name_list.count ("Python")

2

def extend (self, iterable): Adds a list to another list;

>>> A

[1, 7, 2, 9, 3, 8, ' A ', ' B ']

>>> b=[2, ' F ', 3]

>>> a+b

[1, 7, 2, 9, 3, 8, ' A ', ' B ', 2, ' F ', 3]

>>> A.extend (b)

>>> A

[1, 7, 2, 9, 3, 8, ' A ', ' B ', 2, ' F ', 3]

>>>

def index (self, value, Start=none, Stop=none): # Check the first index value of an element in the list;

>>> name_list.index ("Python")

1

def insert (self, Index, p_object): # Inserts an element into the list;

>>> Name_list.insert (3, "Python")

>>> name_list

[' shuoming ', ' python ', ' search ', ' python ', ' python ']

def pop (self, index=none): # Removes the element from the list at the end;

>>> Last_one = Name_list.pop ()

>>> Last_one

' Python '

>>> name_list

[' shuoming ', ' python ', ' search ', ' python ']

def remove (self, value): # Deletes an element, the default is the first value of the specified element;

>>> name_list.remove (' python ')

>>> name_list

[' shuoming ', ' search ', ' python ']

def reverse (self): # flip;

>>> name_list

[' shuoming ', ' search ', ' python ', ' @ ', ' $ ']

>>> Name_list.reverse ()

>>> name_list

[' $ ', ' @ ', ' python ', ' Search ', ' shuoming ']

def sort (self, key=none, reverse=false): # Sort, special characters in front;

>>> name_list

[' shuoming ', ' search ', ' python ', ' @ ', ' $ ']

>>> Name_list.sort ()

>>> Print (name_list)

[' $ ', ' @ ', ' python ', ' Search ', ' shuoming ']



This article is from the "a myriad of simple pleasures of technology to enjoy" blog, please be sure to keep this source http://51enjoy.blog.51cto.com/8393791/1734138

Python--List class

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.