all Python 3Byte sequencesfunction
bytes.rjust
bytes — padding
Right-justify in a field of the given width.
Syntax
b.rjust(...)
For signed numbers the result differs from zfill: rjust with a zero fill puts the zeros before the minus, while zfill inserts them after the sign. Like ljust it never truncates — if the value is already at least as long as width it is returned unchanged — and the fill must be exactly one byte.
Examples
print(b'hi'.rjust(5, b'.')) # → b'...hi'
print(b'7'.rjust(3)) # → b' 7'
print(b'42'.rjust(5, b'0')) # → b'00042'
print(b'hello'.rjust(3, b'.')) # → b'hello'
print(b'hi'.ljust(5, b'.')) # → b'hi...'
print(b'hi'.rjust(5, b'..')) # → TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy