string.rindex(sub,start,end)
Parameter | Description |
---|---|
sub | It's the substring to be searched in the string . |
start | Optional. starting index within the string where search starts. |
end | Optional. ending index within the string where search ends. |
The rindex() method is similar to rfind() method for strings.
The only difference is that rfind() returns -1 if the substring is not found, whereas rindex() throws an exception.
string = 'Let it be, let it be, let it be'result = string.rindex('let it')print("Substring 'let it':", result)result = string.rindex('small')print("Substring 'small ':", result)result = string.rindex('be,')if (result != -1):print("Highest index where 'be,' occurs:", result)else:print("Doesn't contain substring")
**********END OF ARTICLE **********
Comments