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

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

Starting from the right, the rsplit() method splits a string into a list.<\/p>\n

If no “max” parameter is specified, this method will return the same value as split().<\/p>\n

Note:<\/strong> When maxsplit<\/strong> is specified, the list will have the number of elements specified plus one.<\/p>\n

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

string.rsplit(separator, maxsplit)<\/pre>\n

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

separator:<\/strong> This is Optional. This parameter specifies the separator to be used when splitting the string. By default, any whitespace serves as a separator.<\/p>\n

maxsplit:<\/strong> This is Optional. Specifies the number of splits to perform. The default value is -1, which represents “all occurrences.”<\/p>\n

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

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

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

Given string = \"welcome,to,python,programs\"\r\nGiven separator = \",\"\r\nGiven maxsplit value = 1<\/pre>\n

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

The above given string is : welcome,to,python,programs\r\nThe given string after applying rsplit() function:\r\n['welcome,to,python', 'programs']<\/pre>\n

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

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

Given string = \"good morning this is btechgeeks\"<\/pre>\n

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

The above given string is : good morning this is btechgeeks\r\nThe given string after applying rsplit() function:\r\n['good', 'morning', 'this', 'is', 'btechgeeks']<\/pre>\n

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

If you don't give any separator and maxsplit values it takes space,-1 values\r\nrespectively by default.<\/pre>\n

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