您的位置:首页 > 编程语言 > Python开发

python tuple 方法

2016-01-22 14:46 661 查看
元组:

元组的可使用方法没有list 和str这么多:

1: tuple ---: 类方法,转换为元组类型

class
tuple(object):

    """

    tuple() -> empty tuple

    tuple(iterable) -> tupleinitialized from iterable's items

   

    If the argument is a tuple, thereturn value is the same object.

    """
 

2:count ----: 次数;记录值出现的次数

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

使用方法:

t = (11,22,33,44,55,22,44,22)

print(type(t))
print(t.count(22))

###  输出结果
<class 'tuple'>
3

 

3: index ----: 索引 ; 返回值出现第一次的位置(可选参数start:起始位置,stop;结束位置):测试时出现了问题

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

使用方法:

t = (11,22,33,44,55,22,44,22)
#t1 = ('this','is','test')

print(t.index(22))
#print(t1.index(is,10,20))

###  输出结果
1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: