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('-'))
['tic', 'tac', 'toe']
Explanation:
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.
Examples of rsplit() method 1. Splitting String Using Python String rsplit() MethodNote: Splitting a string using Python String rsplit() but without using maxsplit is same as using String split() 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))
['geeks, for, ', 'eeks'] ['geeks@for', 'geeks']
Explanation:
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))
['geeks, for, geeks, pawan'] ['geeks', 'for', 'geeks', 'pawan']
Explanation:
Related Articles:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4