1. 程式人生 > >Python開發(基礎):列表List

Python開發(基礎):列表List

list python

  • List 內置函數

#!/usr/bin/env python
# -*- coding:utf-8 -*-

# class list(object):
#     """
#     list() -> new empty list
#     list(iterable) -> new list initialized from iterable‘s items
#     """
#
#     def append(self, p_object):  # real signature unknown; restored from __doc__
#         在list尾部追加
#         """ L.append(object) -- append object to end """
#         pass
li = [‘alex‘,‘tom‘,‘aric‘,‘tony‘,‘alex‘]
li.append(‘jason‘)
print li
#[‘alex‘, ‘tom‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘]
#     def count(self, value):  # real signature unknown; restored from __doc__
#         返回list中某個值出現的次數
#         """ L.count(value) -> integer -- return number of occurrences of value """
#         return 0
print li.count(‘alex‘)
#     def extend(self, iterable):  # real signature unknown; restored from __doc__
#         將一個可叠代的對象追加到list尾部
#         """ L.extend(iterable) -- extend list by appending elements from the iterable """
#         pass
li.extend((‘steven‘,‘whales‘))
print li
#[‘alex‘, ‘tom‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘]
li.extend(‘Tomcat‘)
#[‘alex‘, ‘tom‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘, ‘t‘]
print li
#     def index(self, value, start=None, stop=None):  # real signature unknown; restored from __doc__
#         返回list中某個值第一次出現的索引位置
#         """
#         L.index(value, [start, [stop]]) -> integer -- return first index of value.
#         Raises ValueError if the value is not present.
#         """
#         return 0
print li.index(‘alex‘)
#0
#   def insert(self, index, p_object):  # real signature unknown; restored from __doc__
#         在list的某個索引位置插入一個值
#         """ L.insert(index, object) -- insert object before index """
#         pass
li.insert(2,‘Andy‘)
print li
#[‘alex‘, ‘tom‘, ‘Andy‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘, ‘t‘]
#     def pop(self, index=None):  # real signature unknown; restored from __doc__
#         """
#         取出list中最後一個索引位置上的值,並刪除
#         L.pop([index]) -> item -- remove and return item at index (default last).
#         Raises IndexError if list is empty or index is out of range.
#         """
#         pass
last_value = li.pop()
print last_value;
print li
#t
#[‘alex‘, ‘tom‘, ‘Andy‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘]
#     def remove(self, value):  # real signature unknown; restored from __doc__
#         """
#         刪除list中某個值,從左往右,只刪除一次,如果存在多個相同的值需要全部刪除,需執行多次
#         L.remove(value) -- remove first occurrence of value.
#         Raises ValueError if the value is not present.
#         """
#         pass
li.remove(‘alex‘)
print li
#[‘tom‘, ‘Andy‘, ‘aric‘, ‘tony‘, ‘alex‘, ‘jason‘, ‘steven‘, ‘whales‘, ‘T‘, ‘o‘, ‘m‘, ‘c‘, ‘a‘]
#     def reverse(self):  # real signature unknown; restored from __doc__
#         反轉
#         """ L.reverse() -- reverse *IN PLACE* """
#         pass
li.reverse()
print li
#[‘a‘, ‘c‘, ‘m‘, ‘o‘, ‘T‘, ‘whales‘, ‘steven‘, ‘jason‘, ‘alex‘, ‘tony‘, ‘aric‘, ‘Andy‘, ‘tom‘]
#     def sort(self, cmp=None, key=None, reverse=False):  # real signature unknown; restored from __doc__
#         """
#         排序
#         L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
#         cmp(x, y) -> -1, 0, 1
#         """
#         pass
li.sort()
print li
#[‘Andy‘, ‘T‘, ‘a‘, ‘alex‘, ‘aric‘, ‘c‘, ‘jason‘, ‘m‘, ‘o‘, ‘steven‘, ‘tom‘, ‘tony‘, ‘whales‘]
#     def __add__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__add__(y) <==> x+y """
#         pass
#
#     def __contains__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__contains__(y) <==> y in x """
#         pass
#
#     def __delitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__delitem__(y) <==> del x[y] """
#         pass
#
#     def __delslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__delslice__(i, j) <==> del x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __eq__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__eq__(y) <==> x==y """
#         pass
#
#     def __getattribute__(self, name):  # real signature unknown; restored from __doc__
#         """ x.__getattribute__(‘name‘) <==> x.name """
#         pass
#
#     def __getitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__getitem__(y) <==> x[y] """
#         pass
#
#     def __getslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__getslice__(i, j) <==> x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __ge__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ge__(y) <==> x>=y """
#         pass
#
#     def __gt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__gt__(y) <==> x>y """
#         pass
#
#     def __iadd__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__iadd__(y) <==> x+=y """
#         pass
#
#     def __imul__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__imul__(y) <==> x*=y """
#         pass
#
#     def __init__(self, seq=()):  # known special case of list.__init__
#         """
#         list() -> new empty list
#         list(iterable) -> new list initialized from iterable‘s items
#         # (copied from class doc)
#         """
#         pass
#
#     def __iter__(self):  # real signature unknown; restored from __doc__
#         """ x.__iter__() <==> iter(x) """
#         pass
#
#     def __len__(self):  # real signature unknown; restored from __doc__
#         """ x.__len__() <==> len(x) """
#         pass
#
#     def __le__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__le__(y) <==> x<=y """
#         pass
#
#     def __lt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__lt__(y) <==> x<y """
#         pass
#
#     def __mul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__mul__(n) <==> x*n """
#         pass
#
#     @staticmethod  # known case of __new__
#     def __new__(S, *more):  # real signature unknown; restored from __doc__
#         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
#         pass
#
#     def __ne__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ne__(y) <==> x!=y """
#         pass
#
#     def __repr__(self):  # real signature unknown; restored from __doc__
#         """ x.__repr__() <==> repr(x) """
#         pass
#
#     def __reversed__(self):  # real signature unknown; restored from __doc__
#         """ L.__reversed__() -- return a reverse iterator over the list """
#         pass
#
#     def __rmul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__rmul__(n) <==> n*x """
#         pass
#
#     def __setitem__(self, i, y):  # real signature unknown; restored from __doc__
#         """ x.__setitem__(i, y) <==> x[i]=y """
#         pass
#
#     def __setslice__(self, i, j, y):  # real signature unknown; restored from __doc__
#         """
#         x.__setslice__(i, j, y) <==> x[i:j]=y
#
#                    Use  of negative indices is not supported.
#         """
#         pass
#
#     def __sizeof__(self):  # real signature unknown; restored from __doc__
#         """ L.__sizeof__() -- size of L in memory, in bytes """
#         pass
#
#     __hash__ = None

本文出自 “小冰” 博客,請務必保留此出處http://wbb827.blog.51cto.com/6948425/1933505

Python開發(基礎):列表List