All String methods

Youtube Live session on Tkinter

Find the rightmost matching of search string and return the position
main_string.rindex(search_string, start, end)
Required, String to be searched and position is returned if found.
Optional, Starting position of search , by default it is from 0 or starting position of string
Optional , ending position of search, by default it is end of the string.

This is case sensitive search
my_str='Welcome to plus2net.com Python section'
print(output) # output is 20
Using optional parameters start and end.
my_str='Welcome to plus2net.com Python section'
print(output) # output is 20
If search string is not found then value error is generated.
my_str='Welcome to plus2net.com Python section'
ValueError                        Traceback (most recent call last)
 in ()
      1 my_str='Welcome to plus2net.com Python section'
----> 2 output=my_str.rindex('co',10,21)
      3 print(output)

ValueError: substring not found
rindex() method raise an exception if searched string is not found but rfind() returns -1 if searched string is not found. That is the main difference between rindex() and rfind()

All String methods

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer