Python Glossary Русский

all Python 3Byte sequencesfunction

bytearray.append

bytearray — mutating

Append a single byte (int 0–255) in place.

Syntax

ba.append(...)

The argument is an int in range 0–255, not a bytes object: ba.append(b'c') raises TypeError, so use ba.append(99) or ba += b'c'. This mirrors the fact that indexing a bytearray yields an int; a value outside 0–255 raises ValueError, and appending itself is amortised O(1).

Examples

ba = bytearray(b'ab')
ba.append(99)
print(ba)   # → bytearray(b'abc')

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy