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