1 个回答|223 次阅读
有两个内置方法可用
1、count()方法可以返回某值在元组中出现的次数
例如,返回7在元组中的次数
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.count(7)
print(x)
执行结果:
2
2、index()方法,返回某值在元组中第一个匹配项的位置
例如
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.index(8)
print(x)
执行结果:
3
请先 登录 后评论