Bytearray Methods

bytearray.join()

Concatenate the binary items in an iterable, inserting the receiver between adjacent items. An empty iterable yields empty data; a single item needs no separator. Accepts bytes, bytearray and contiguous memoryview items. Integers and Unicode strings are not binary buffers and raise TypeError. Returns a new mutable buffer.

Formal Syntax & Structure

python syntaxpython
data.join(iterable, /)

Parameters & Attributes

NameTypeDescription
iterableIterable[bytes-like]Iterable of binary buffers; text and integer items are not accepted.

Return Value

bytearray

bytearray containing concatenated items separated by the receiver.

Working Example

Example Snippetpython
print(bytearray(b'|').join([b'head', b'body', b'end']))print(bytearray(b':').join([bytearray(b'A'), memoryview(b'B')]))print(bytearray(b'-').join((bytes([x]) for x in (65,66,67))))
Python Reference