Find index of last occurrence of a substring in a string

前端 未结 9 1534
挽巷
挽巷 2020-11-27 10:36

I want to find the position (or index) of the last occurrence of a certain substring in given input string str.

For example, suppose the input string is

9条回答
  •  执念已碎
    2020-11-27 11:03

    Try this:

    s = 'hello plombier pantin'
    print (s.find('p'))
    6
    print (s.index('p'))
    6
    print (s.rindex('p'))
    15
    print (s.rfind('p'))
    

提交回复
热议问题