1 目录
- count
- index
2 说明
count
def count(self, value): # real signature unknown; restored from __doc__ """ T.count(value) -> integer -- return number of occurrences of value """ return 0
index
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
3 例程
a_tuple = (1, 'apple', [2, 'pear'], {3: 'strawberry'}, (4, 'lychee'))
pear_count = a_tuple.count('pear')
print('pear_count: ', pear_count)
# pear_count: 0
idx_4_lychee = a_tuple.index((4, 'lychee'))
print('idx of (4, \'lychee\') is: ', idx_4_lychee)
# idx of (4, 'lychee') is: 4
try:
idx_lychee = a_tuple.index('lychee')
print('idx of \'lychee\' is: ', idx_lychee)
except Exception as e:
print(e)
# tuple.index(x): x not in tuple