站长资讯网
最全最丰富的资讯网站

python中index的用法是什么

python中index的用法是什么

index()

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

>>> 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

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

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号