str.rsplit() Right split
Last updated: 2026-09-22
str.rsplit() Right split
str.rsplit(sep=None, maxsplit=-1) splits from the right up to maxsplit times.
| Category | String Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
str.rsplit(sep=None, maxsplit=-1)
⚙️ Parameters
| sep Optional | Separator; None means split on any run of whitespace.(Default:None) |
|---|---|
| maxsplit Optional | Maximum number of splits; -1 means no limit.(Default:-1) |
Returns:list[str]. The substrings produced by splitting from the right.
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
['a,b', 'c', 'd']
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is the difference between rsplit() and split()?
Asplit() splits from left to right, rsplit() from right to left. Without maxsplit, both give the same result.
QWhat effect does maxsplit have?
A'a,b,c,d'.rsplit(',', 2) splits twice from the right, giving ['a,b', 'c', 'd']. Often used to take only the last N segments.
QHow does it split when no separator is given?
AWith sep=None it splits on any run of whitespace, matching split(); consecutive whitespace is merged.