all Python 3Strings (str)function
str.rjust
alignment
Right-justify the string in a field of the given width, padded on the left.
Syntax
s.rjust(width[, fillchar])
When width is not greater than the current length nothing gets truncated — the original string comes back untouched, so rjust cannot squeeze text into N columns. The fillchar argument must be exactly one character, otherwise you get a TypeError. For signed numbers use zfill instead: rjust with '0' puts the zeros in front of the minus, not after it.
Examples
print('hi'.rjust(5, '.')) # → ...hi
print('42'.rjust(5, '0')) # → 00042
print('hello'.rjust(3)) # → hello
See also
Open in the full glossarydocs.python.orgReport an inaccuracy