Bytearray Methods

bytearray.extend()

Append the byte values from an iterable or supported binary buffer to the existing bytearray. Each iterable item must support integer indexing and be within 0–255. Text and a bare integer are not accepted. Self-extension duplicates the current data. An active memoryview export blocks growth, but an empty extension may succeed. CPython 3.13.5 validates ordinary iterable items before appending; an invalid item or a raising iterator leaves the original bytes unchanged in the tested cases. Do not assume rollback of arbitrary user-code side effects. Noncontiguous memoryview inputs are rejected in the tested runtime.

Formal Syntax & Structure

python syntaxpython
data.extend(iterable_of_ints, /)

Parameters & Attributes

NameTypeDescription
iterable_of_intsIterable[int] | bytes-likeIterable of integer byte values or supported binary buffer.

Return Value

None

None; modifies the existing buffer.

Working Example

Example Snippetpython
data = bytearray(b"AB")print(data.extend([0, 255]))data.extend(b"CD")data.extend(n for n in (69, 70))print(list(data))
Python Reference