当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

在Python中查找字符串中最后一次出现的子字符串的索引

  1. s = 'What is Canada famous for?'
  2. print(s.find('f'))
  3. print(s.index('f'))
  4. print(s.rindex('f'))
  5. print(s.rfind('f'))

Output:

  1. 15
  2. 15
  3. 22
  4. 22