all Python 3Byte sequencesfunction
bytes.ljust
bytes — padding
Left-justify in a field of the given width.
Syntax
b.ljust(...)
When width is not greater than the current length, the original bytes come back untouched — there is no truncation, so one long value will break the alignment of a hand-made table. The fill argument must be exactly one byte, otherwise you get a TypeError. Nothing is modified in place: a new copy is returned.
Examples
print(b'hi'.ljust(5, b'.')) # → b'hi...'
print(b'hi'.ljust(5)) # → b'hi '
print(b'7'.ljust(4, b'0')) # → b'7000'
print(b'hello'.ljust(3)) # → b'hello'
print(b'hi'.rjust(5, b'.')) # → b'...hi'
print(b'hi'.ljust(5, b'..')) # → TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy