rfind()

Returns the rightmost matching position of the search string in a main string
main_string.rfind(search_string, start, end)
search_string : Required, String to be searched and position is returned if found.
start : Optional, Starting position of search , by default it is from 0 or starting position of string
end : Optional , ending position of search, by default it is end of the string.
my_str='Welcome to plus2net.com Python section'
output=my_str.rfind('co') 
print(output) # output is 20
Using optional parameters start and end. If not matching is found then output is -1
my_str='Welcome to plus2net.com Python section'
output=my_str.rfind('co',10,21)
print(output) # output is -1

my_str='Welcome to plus2net.com Python section'
output=my_str.rfind('co',10,22)
print(output) # output is 20
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 rfind() and rindex()

All String methods


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







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 Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer