Bytes Methods

bytes.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 immutable bytes.

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

bytes

bytes containing concatenated items separated by the receiver.

Working Example

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