Bytearray Methods

bytearray.split()

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 left; 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 leading whitespace. Empty explicit separators raise ValueError. Non-ASCII whitespace encodings are not recognized. Each field is an independent bytearray.

Formal Syntax & Structure

python syntaxpython
data.split(sep=None, maxsplit=-1)

Parameters & Attributes

NameTypeDescription
sepbytes-like | NoneNonempty literal separator; None selects ASCII whitespace splitting.
maxsplitintMaximum splits; negative means unlimited.

Return Value

list[bytearray]

List of bytearray fields in original order.

Working Example

Example Snippetpython
print(bytearray(b'a:b:c').split(b':', 1))print(bytearray(b'  a  b  ').split())print(bytearray(b'a,,b,').split(b','))
Python Reference