all Python 3Byte sequencesfunction
bytearray.split
bytearray — split and join
Split on a separator (whitespace by default).
Syntax
ba.split(...)
You cannot split into individual bytes by passing an empty separator: split(b'') raises ValueError. For per-byte access use slices, or list(ba), which yields integers rather than byte chunks. The pieces in the returned list are independent bytearray copies — mutating them leaves the original object untouched.
Examples
print(bytearray(b'a b').split()) # → [bytearray(b'a'), bytearray(b'b')]
print(bytearray(b'a,b,c').split(b',')) # → [bytearray(b'a'), bytearray(b'b'), bytearray(b'c')]
print(bytearray(b'a,b,c').split(b',', 1)) # → [bytearray(b'a'), bytearray(b'b,c')]
print(len(bytearray(b' one two ').split())) # → 2
print(bytearray(b'a,,b').split(b',')) # → [bytearray(b'a'), bytearray(b''), bytearray(b'b')]
print(bytearray(b' ').split()) # → []
See also
Open in the full glossarydocs.python.orgReport an inaccuracy