qiang6313669

index()的用法:

def index(self, sub, start=None, end=None): 

S.index(sub[, start[, end]]) ->int

        

返回在S中找到子字符串sub的最低索引,

使sub包含在S[start:end]中。可选

参数start和end被解释为切片表示法。        

当找不到子字符串时引发ValueError。

 

find()的用法:

def find(self, sub, start=None, end=None): 

b .查找(sub[, start[, end]]) ->int

        

返回在B中找到子sub的最低索引,

使sub包含在B中[start,end]。可选

参数start和end被解释为切片表示法。

失败时返回-1。

总结:

使用index()时,如果在字符串中没有找到对应字符,则返回一个报错,而使用find()时,如果在字符串中没有找到对应字符,则返回-1,不抛出报错。

 

 

 

 




posted on 2021-07-17 09:28  夏夏夏天的西瓜  阅读(82)  评论(0编辑  收藏  举报

分类:

技术点:

相关文章:

  • 2021-10-29
  • 2022-12-23
  • 2021-11-10
  • 2021-11-21
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2021-05-11
  • 2021-11-08
  • 2021-09-29
  • 2021-07-29
  • 2021-05-06
  • 2021-08-23
  • 2021-07-26
相关资源
相似解决方案