Bytearray Methods

bytearray.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. All three fields are new bytearray objects; the separator is copied.

Formal Syntax & Structure

python syntaxpython
data.rpartition(sep, /)

Parameters & Attributes

NameTypeDescription
sepbytes-likeNonempty literal binary separator.

Return Value

tuple[bytearray, bytearray, bytearray]

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

Working Example

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