{"id":24487,"date":"2021-10-21T10:04:17","date_gmt":"2021-10-21T04:34:17","guid":{"rendered":"https:\/\/python-programs.com\/?p=24487"},"modified":"2021-11-05T17:41:16","modified_gmt":"2021-11-05T12:11:16","slug":"python-string-rfind-method-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-rfind-method-examples\/","title":{"rendered":"Python String rfind() Method Examples"},"content":{"rendered":"

In the previous article, we have discussed Python Program for partition() Function<\/a>
\nrfind() Function in Python:<\/strong><\/p>\n

The rfind() method gives the position of the last occurrence of the specified value.<\/p>\n

If the value cannot be found, the rfind() method returns -1.<\/p>\n

The rfind() method is nearly identical to the rindex() method.<\/p>\n

Syntax:<\/strong><\/p>\n

string.rfind(value, start, end)<\/pre>\n

Parameters<\/strong><\/p>\n

value:<\/strong> This is required. The value to look for<\/p>\n

start:<\/strong> This is optional. Where to begin your search. The default value is 0.<\/p>\n

end:<\/strong> This is optional. Where to put an end to the search. The default value is to the end of the string.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given string =  \"welcome to python learning platform\"\r\nGiven value = \"p\"<\/pre>\n

Output:<\/strong><\/p>\n

The result after applying rfind() function on the given string =  27<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given string = \"welcome to python learning platform\"\r\nGiven value = \"o\"\r\nGiven start index = 1\r\nGiven end index = 8<\/pre>\n

Output:<\/strong><\/p>\n

The result after applying rfind() function on the given string =  4<\/pre>\n

String rfind() Method Examples\u00a0in Python<\/h2>\n