元组:
元组的可使用方法没有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