+

str.rfind in Python

Returns the highest index at which the end of the specified substring is found in the source.

str.rfind (sub [, start [, end]])

-> < span id = "area_func_result"> int

sub - Substring whose final placement index you want to determine.

start = 0 - Index the beginning of the slice in the source string where you want to find the substring.

end = None - The index of the end of the slice in the source string where you want to find the substring. 


If the substring is not found, it returns -1
Search for a substring is performed from right to left (hence the r prefix in the method name rfind )

  my_str = `barbarian` 
my_str.rfind (` bar`) # 3
my_str.rfind (`bar`, 1) # 3
my_str.rfind (` bar`, 1, 2) # -1

The optional parameters start and end can take any values ​​supported by the mechanism slices .

Notes

See also: str.find () .

Get Solution for free from DataCamp guru