Reputation: 10149
Wondering if there is a neat API in Python to search a string from backward (from a specific position in a string), for example, in string "Hello StackOverflow Hello Python", suppose I want to find the index of sub-string "Hello" which is previous to sub-string "Python"?
thanks in advance, Lin
Upvotes: 0
Views: 821
Reputation: 15310
Yes, it's called str.rindex()
. It takes arguments sub
- a substring to look for, start
- a starting position, and end
.
It is the r
everse of the index
function. There are some others, like rsplit
, too.
Upvotes: 3