元组tuple常用方法

    元组tuple的功能类似与列表,元组有的功能,列表都有,列表有的,元组不一定有,下面来看看元组具有的功能:

    1.count(self,value)

    def count(self, value): # real signature unknown; restored from __doc__
    """ T.count(value) -> integer -- return number of occurrences of value """
    return 0

    count(self,value)统计元组中值的个数,实例如下:

    >>> t1 = (11,22,88)
  >>> t1[1]
  22
  >>> t1.count(22)
  1  

    2.index(self,value,start=None,stop=None)

    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
    """
    T.index(value, [start, [stop]]) -> integer -- return first index of value.
    Raises ValueError if the value is not present.
    """
    return 0
 

    index(self,value,start=None,stop=None)查找指定值在元组中的索引,实例如下:

    >>> t1 = (11,22,88)
    >>> t1.index(88)
  2
    其实元组中的方法都是列表中的方法,元组由自己的性质,因为很多方法没有。

原文地址:https://www.cnblogs.com/gengcx/p/6752341.html