查询字符串中是否包含子字符串。如果包含,返回子字符串开始的索引值;否则,返回-1

语法

str.find(sub[, start[, end]])

参数

  • sub:待查询的子字符串
  • start:开始索引,可选,默认为0
  • end:结束索引,可选,默认为字符串的长度

返回

若含有子字符串就返回开始的索引值,否则返回-1

示例

>>> str = 'hello'
>>> str.find('o')
4
>>> str.find('a')
-1

引用

https://docs.python.org/3/library/stdtypes.html?highlight=find#str.find

相关文章:

  • 2022-12-23
  • 2021-09-02
  • 2021-12-12
  • 2021-11-28
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-12-19
  • 2021-12-29
  • 2021-11-03
  • 2021-06-07
  • 2021-05-18
相关资源
相似解决方案