Python Glossary Русский

all Python 3Byte sequencesfunction

bytearray.rjust

bytearray — padding

Right-justify in a field of the given width.

Syntax

ba.rjust(...)

The number is the total field width, not the count of padding bytes, and oversized data is never truncated — slice it yourself if you need a hard width. Padding with rjust(n, b'0') is not the same as zfill: rjust knows nothing about signs and turns b'-42' into b'00-42', while zfill keeps the minus in front and inserts the zeros after it.

Examples

print(bytearray(b'hi').rjust(5, b'.'))   # → bytearray(b'...hi')
print(bytearray(b'42').rjust(6))   # → bytearray(b'    42')
print(bytearray(b'7').rjust(3, b'0'))   # → bytearray(b'007')
print(bytearray(b'hello').rjust(3, b'.'))   # → bytearray(b'hello')
print(bytearray(b'hi').ljust(5, b'.'))   # → bytearray(b'hi...')

See also

Open in the full glossarydocs.python.orgReport an inaccuracy