Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
txt = "apple, banana, cherry" # setting the maxsplit parameter to 1, will return a list with 2 elements! x = txt.rsplit(", ", 1) print(x) # note that the result has only 2 elements "apple, banana" is the first element, and "cherry" is the last.
['apple, banana', 'cherry']