Bytes Methods
bytes.rsplit()
Split binary data at a literal nonempty bytes-like separator, or at runs of ASCII whitespace when sep is None. With a nonnegative split limit, choose matches from the right; output fields remain in original order. Explicit separators preserve empty fields, whereas whitespace mode discards edge whitespace when splitting without a limit. With maxsplit=0, whitespace mode only removes trailing whitespace. Empty explicit separators raise ValueError. Non-ASCII whitespace encodings are not recognized. Fields are immutable bytes.
Formal Syntax & Structure
python syntaxpython
data.rsplit(sep=None, maxsplit=-1)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sep | bytes-like | None | Nonempty literal separator; None selects ASCII whitespace splitting. |
| maxsplit | int | Maximum splits; negative means unlimited. |
Return Value
list[bytes]
List of bytes fields in original order.
Working Example
Example Snippetpython
print(bytes(b'a:b:c').rsplit(b':', 1))print(bytes(b' a b ').rsplit())print(bytes(b'a,,b,').rsplit(b','))