30-Days-Of-Python icon indicating copy to clipboard operation
30-Days-Of-Python copied to clipboard

04_strings: rindex

Open statnaia opened this issue 3 years ago • 0 comments

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.

statnaia avatar Jul 19 '22 14:07 statnaia