0

How this code work ?

How this code results 6 ? I want to know logical procedure of getting 6 by rfind https://code.sololearn.com/cWw1GxTb2Djr/?ref=app

10th Dec 2017, 8:42 PM
NIMA
NIMA - avatar
5 Respuestas
+ 11
This shows you the index number of the first character of the string you were looking for. It returns the last found occurence (if found again) or -1 if not found at all: Mis[si]s[si]ppi -----3^--6^ The second argument specifies the index to start the search from.
10th Dec 2017, 9:04 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
rfind is looking for the last substring that matches the given parameter and returns the index of the first character of that substring within the long string. In this case, the index of the start of the latest "si" in "Mississippi" is indeed 6 (as index starts at 0 )
10th Dec 2017, 8:59 PM
ifl
ifl - avatar
+ 3
3 is the start index (see the comment on your code) Edit. You changed your code from public to private, so the comment is no longer accessible. Here it is: str.rfind(sub, start, end) returns the highest index of the substring (i.e. highest index number of the first character of the substring). 'Mississippi' has a substring 'si' at index 3 and 6 (remember the first index is 0), so the return value is 6. You have included a start index of 3 (which is the index of the second 's'), but that doesn't affect the outcome, because the highest index of 'si' (6) is higher than the start index (3). If you had made the start index 7, it would have returned -1, meaning 'not found'.
12th Dec 2017, 6:23 AM
David Ashton
David Ashton - avatar
+ 2
rfind returns the latest position where the Substring begins. In Mississippi "M" is letter 0. The second "si" starts with letter 6.
10th Dec 2017, 8:59 PM
Sebastian Keßler
Sebastian Keßler - avatar
0
thanks for descriptions, what 3 means ?
10th Dec 2017, 9:02 PM
NIMA
NIMA - avatar