Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.rsplit

Splits a string starting at the right, subject to the split limit.

Version: Python 3.14; repository image, production runtime not attested

Syntax

s.rsplit(sep=None, maxsplit=-1)

Splits a string starting at the right, subject to the split limit.

With an explicit separator a trailing delimiter creates a final empty field.

With no separator, whitespace runs delimit fields; the default split count is unlimited. One split from the right on a:b:c leaves the left substring a:b intact. The explicit trailing colon in a: yields an empty final field.

assert "a:b:c".rsplit(":", 1) == ["a:b", "c"] and "a:".rsplit(":")[-1] == ""

Examples

print("a:b:c".rsplit(":", 1))
print("a:".rsplit(":", 1))

Result

['a:b', 'c']
['a', '']

With no separator, whitespace runs delimit fields; the default split count is unlimited. One split from the right on a:b:c leaves the left substring a:b intact. The explicit trailing colon in a: yields an empty final field.

Sources