Python String rsplit() Method (original) (raw)

Last Updated : 21 Apr, 2025

**Python String rsplit() method returns a list of strings after breaking the given string from the right side by the specified separator. It’s similar to the split() method in Python, but the difference is that rsplit() starts splitting from the end of the string rather than from the beginning. Example:

Python `

s = "tic-tac-toe" print(s.rsplit('-'))

`

Output

['tic', 'tac', 'toe']

**Explanation:

Syntax of rsplit() method

str.rsplit(separator, maxsplit)

**Parameters:

**Return Type: Returns a _list of strings after breaking the given string from the right side by the specified separator.

**Error: We will not get any error even if we are not passing any argument.

**Note: Splitting a string using Python String rsplit() but without using maxsplit is same as using String split() Method

Examples of rsplit() method

1. Splitting String Using Python String rsplit() Method

Splitting Python String using different separator characters.

Python `

splits the string at index 12 i.e.: the last occurrence of g

word = 'geeks, for, geeks' print(word.rsplit('g', 1))

Splitting at '@' with maximum splitting as 1

word = 'geeks@for@geeks' print(word.rsplit('@', 1))

`

Output

['geeks, for, ', 'eeks'] ['geeks@for', 'geeks']

**Explanation:

2. Splitting a String using a multi-character separator argument.

Here we have used more than 1 character in the separator string. Python String rsplit() Method will try to split at the index if the substring matches from the separator.

Python `

word = 'geeks, for, geeks, pawan'

maxsplit: 0

print(word.rsplit(', ', 0))

maxsplit: 4

print(word.rsplit(', ', 4))

`

Output

['geeks, for, geeks, pawan'] ['geeks', 'for', 'geeks', 'pawan']

**Explanation:

**Related Articles: