30-Days-Of-Python
30-Days-Of-Python copied to clipboard
04_strings: rindex
Rindex() returns the highest index of the substring inside the string, not the end index of a substring. Therefore the output of this command is the same, as the output of the index() command, shown a bit earlier (index number 7) because the substring 'da' is found only once in the original string.
But for the following example:
challenge = 'thirty days of daily python'
sub_string = 'da'
print(challenge.rindex(sub_string))
the output is 15 because it can be found twice in the original string.