String Methods
rsplit()
Split text into a list, starting from the right when a limit is used.
str.rsplit(sep=None, maxsplit=-1)
Split text into a list, starting from the right when a limit is used.
Arguments
Parameters
| Name | Description |
|---|---|
| sep | The separator to split on; if omitted, whitespace is used. |
| maxsplit | Maximum number of splits; -1 means no limit. |
Result
Returns
A list of pieces from the string.
Run it
Try it
Run it and change it
text = "a,b,c"
print(text.rsplit(",", 1)) Output
Press Run to see what it prints.Worth knowing
- With a
maxsplitlimit,rsplit()keeps the left part together.split()applies the limit from the left instead.