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

In the previous article, we have discussed Python String rfind() Method Examples<\/a>
\nrindex() Function in Python:<\/strong><\/p>\n

The rindex() method returns the location of the last occurrence of the specified value.<\/p>\n

If the value is not found, the rindex() method throws an exception.<\/p>\n

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

Note:<\/strong> The only difference is rindex() method throws an exception if the value is not found whereas rfind() returns a value -1.<\/strong><\/p>\n

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

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

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

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

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

end:<\/strong>\u00a0This 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 rindex() function on the given string =  27<\/pre>\n

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

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

Given string = \"good morning btechgeeks\"\r\nGiven value = 'e'\r\nGiven start index = 3\r\nGiven end index = 16<\/pre>\n

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

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

\u00a0String rindex() Method Examples\u00a0in Python<\/h2>\n