Skip to content
Built-in Functions

bytearray()

Create a mutable sequence of bytes.

bytearray(source=b"")

bytearray() stores byte values from 0 through 255. Unlike bytes, you can change individual byte values after creating it.

Parameters

NameDescription
sourceOptional bytes, an iterable of integers, a string with an encoding, or a size.

Returns

A new mutable bytearray object.

Try it

Run it and change it
letters = bytearray(b"cat")
letters[0] = 67
print(letters)

Related entries