{"id":24519,"date":"2021-10-21T10:04:22","date_gmt":"2021-10-21T04:34:22","guid":{"rendered":"https:\/\/python-programs.com\/?p=24519"},"modified":"2021-11-05T18:26:31","modified_gmt":"2021-11-05T12:56:31","slug":"python-string-rpartition-method-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-rpartition-method-examples\/","title":{"rendered":"Python String rpartition() Method Examples"},"content":{"rendered":"

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

The rpartition() method looks for the last occurrence of a string and splits it into a tuple with three elements.<\/p>\n

The part preceding the specified string is contained in the first element.<\/p>\n

The specified string is contained in the second element.<\/p>\n

The part following the string is contained in the third element.<\/p>\n

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

string.rpartition(value)<\/pre>\n

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

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

If the specified value is not found, the rpartition() method returns a tuple containing the following values: 1 – an empty string, 2 – an empty string, 3 – the entire string.<\/p>\n

For example:<\/strong><\/p>\n

gvn_str = \"welcome to python learning platform\"\r\nrslt_tupl = gvn_str.rpartition(\"java\")\r\nprint(rslt_tupl)\r\n<\/pre>\n

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

('', '', 'welcome to python learning platform')<\/pre>\n

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

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

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

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

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

The result tuple after applying rpartition() function on the given string : \r\n('welcome to python learning platform, ', 'python', ' programs')<\/pre>\n

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

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

Given string = \"good morning all\"\r\nGiven value = \"all\"<\/pre>\n

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

The result tuple after applying rpartition() function on the given string : \r\n('good morning ', 'all', '')<\/pre>\n

String rpartition() Method Examples in Python<\/h2>\n