Home >>Python String Methods >Python String rsplit() Method

Python String rsplit() Method

Python String rsplit() Method

Python String rsplit() Method splits a string and returns a list, starting from the right side by the Specified separator. It will same as the split() method except splitting from the right.

Syntax:
string.rsplit(separator, maxsplit)

Parameter Values

Parameter Description
separator It is Optional and is used to Specifies the separator to use when splitting the string.
maxsplit It is Optional. Specifies how many times number of splits to do. -1 is the default value.
Here is an example of Python String rsplit() Method:

txt = "red, blue , orange, green"
x = txt.rsplit(", ")
print(x)

Output:
['red', 'blue ', 'orange', 'green']
Example 2:

str = "javaScript is a scripting language"   
str2 = str.rsplit('i')  
print(str2)

Output:
['javascr', 'pt ', 's a scr', 'pt', 'ng language']

No Sidebar ads