index()
一般用處是在序列中檢索參數(shù)并返回第一次出現(xiàn)的索引,沒找到就會報錯,比如:
>>> t=tuple('Allen') >>> t ('A', 'l', 'l', 'e', 'n') >>> t.index('a') Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> t.index('a') ValueError: tuple.index(x): x not in tuple >>> t.index('e') 3 >>> t.index('l') 1
但參數(shù)可能會出現(xiàn)很多次,要如何做呢?