Bytearray Methods

bytearray.rjust()

Pad data to at least width bytes, aligned right. The fill argument must be a one-byte bytes or bytearray object in CPython 3.13.5; a memoryview is rejected. Width counts bytes, not decoded characters or terminal columns. Widths no larger than the current length do not truncate. Returns a new bytearray even without padding.

Formal Syntax & Structure

python syntaxpython
data.rjust(width, fillbyte=b" ", /)

Parameters & Attributes

NameTypeDescription
widthintMinimum total length in bytes.
fillbytebytes | bytearrayExactly one padding byte; default ASCII space.

Return Value

bytearray

bytearray padded to at least width bytes.

Working Example

Example Snippetpython
print(bytearray(b'AB').rjust(6, b'.'))print(bytearray(b'ABC').rjust(7))print(bytearray(b'ABC').rjust(2))
Python Reference