index用于返回指定值在序列的第一个位置

 

序列.index(值,开始索引,结束索引)

开始索引默认为0,可不传

结束索引默认为序列长度,可不传

>>> str = 'abc'
>>> str.index('a')
0
>>> str.index('b')
1
>>> str.index('bc')
1
>>> str.index('a',1)
Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    str.index('a',1)
ValueError: substring not found
>>> str.index('b',1)
1

 

posted on 2022-04-22 10:32  12345zjl  阅读(642)  评论(0编辑  收藏  举报