当前位置:  首页>> 技术小册>> Python合辑2-字符串常用方法

22、rfind()

类似于find()函数,返回字符串最后一次出现的位置,如果没有匹配项则返回-1。

  1. s = 'Machine Learning'
  2. idx = s.rfind('a')
  3. print(idx)
  4. print(s[idx:])
  5. # 10
  6. # arning