YouTip LogoYouTip

Python3 String Rindex

# Python3.x Python3 rindex() Method [![Image 3: Python3 Strings](#) Python3 Strings](#) * * * ## Description The rindex() method returns the highest index in the string where the substring str is found. If the substring is not found, it raises a ValueError. You can optionally specify the [beg:end] range to limit the search. ## Syntax The syntax for the rindex() method is: str.rindex(str, beg=0 end=len(string)) ## Parameters * str -- The substring to search for. * beg -- The starting index for the search. Defaults to 0. * end -- The ending index for the search. Defaults to the length of the string. ## Return Value Returns the highest index in the string where the substring str is found. Raises a ValueError if the substring is not found. ## Example The following example demonstrates the usage of the rindex() function: #!/usr/bin/python3 str1 = "this is really a string example....wow!!!" str2 = "is"print (str1.rindex(str2))print (str1.rindex(str2,10)) The output of the above example is: 5Traceback (most recent call last): File "test.py", line 6, in print (str1.rindex(str2,10))ValueError: substring not found * * Python3 Strings](#)
← Python3 String RstripPython3 String Max β†’