Bytes Methods

bytes.rpartition()

Split at the last occurrence of a nonempty binary separator. Return three fields in original order: before, separator, after. On absence, place the original data in the third field and use empty sequences for the other two. An empty separator raises ValueError. The outside fields are bytes. On a match, the middle field is the supplied separator itself in CPython 3.13.5, so a mutable separator or memoryview can remain aliased. On absence, all fields are bytes.

Formal Syntax & Structure

python syntaxpython
data.rpartition(sep, /)

Parameters & Attributes

NameTypeDescription
sepbytes-likeNonempty literal binary separator.

Return Value

tuple[bytes, bytes-like, bytes]

Three fields: before, separator, after; absent-separator result depends on search direction.

Working Example

Example Snippetpython
print(bytes(b'a:b:c').rpartition(b':'))print(bytes(b'abc').rpartition(b':'))print(bytes(b':').rpartition(b':'))
Python Reference