String Methods
str.rsplit()
Split into a list of fields, selecting up to maxsplit separator occurrences from the right. Explicit nonempty sep preserves empty fields between consecutive separators and at the edges. None groups consecutive whitespace and omits edge empty fields; empty or whitespace-only input produces an empty list in that mode. With maxsplit=0 and sep=None only the corresponding outer whitespace run is removed. A negative maxsplit is unlimited. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.rsplit(sep=None, maxsplit=-1)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sep | str | None | Literal nonempty separator, or None for whitespace mode. |
| maxsplit | int | Maximum number of splits; negative means unlimited. |
Return Value
list[str]
Fields in original left-to-right order.
Working Example
Example Snippetpython
print("a:b:c".rsplit(":", 1))print(" a b ".rsplit())print("a,,b,".rsplit(","))