all Python 3Byte sequencesfunction
bytearray.extend
bytearray — mutating
Extend with bytes from an iterable in place.
Syntax
ba.extend(...)
It expects an iterable of ints in 0–255: bytes and bytearray work, a str does not — ba.extend('ab') fails, encode the text first. A single number is rejected too, since it is not iterable; use append for that.
Examples
ba = bytearray(b'ab')
ba.extend(b'cd')
print(ba) # → bytearray(b'abcd')
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy