descriptive
The Python rindex() method returns the index of the last occurrence of a substring in a string, which is the same as the rfind() method, except that an exception is thrown if the substring is not in the string.
grammatical
rindex() method syntax:
(sub[,start=0[,end=len(S)]])
parameters
- sub -- specifies the sub-string to retrieve
- S -- parent string
- start -- optional parameter, where to start searching, default is 0. (can be specified separately)
- end -- Optional parameter to end the lookup position, defaults to the length of the string. (cannot be specified separately)
return value
Returns the index position of the last occurrence of the substring in the string, if there is no match then an exception is thrown.
an actual example
The following example shows how the rindex() method is used:
#!/usr/bin/python3 S1 = "this is really a string example....wow!!!" S2 = "is" print ((S2)) print ((S2,10))
The output of the above example is as follows:
5
Traceback (most recent call last):
File "", line 6, in <module>
print ((str2,10))
ValueError:substring not found
to this article on the Python rindex () method case details of the article is introduced to this, more related Python rindex () method content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!