PHP前端开发

python中index的用法是什么

百变鹏仔 1个月前 (01-22) #Python
文章标签 python

index()

一般用处是在序列中检索参数并返回第一次出现的索引,没找到就会报错,比如:  

&gt;&gt;&gt; t=tuple('Allen')&gt;&gt;&gt; t('A', 'l', 'l', 'e', 'n')&gt;&gt;&gt; t.index('a')Traceback (most recent call last): File "<pyshell>", line 1, in <module>  t.index('a')ValueError: tuple.index(x): x not in tuple&gt;&gt;&gt; t.index('e')3&gt;&gt;&gt; t.index('l')1</module></pyshell>

但参数可能会出现很多次,要如何做呢?