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.
Parameters
| Name | Description |
|---|---|
| sep | The separator to split on; if omitted, whitespace is used. |
| maxsplit | Maximum number of splits; -1 means no limit. |
Returns
A list of pieces from the string.
Try it
Run it and change it
text = "a,b,c"
print(text.rsplit(",", 1))
Worth knowing
- With a
maxsplitlimit,rsplit()keeps the left part together.split()applies the limit from the left instead.