Chapters
Python114 chapters

ReferenceString methods

str.rjust()

Pads on the left so the text sits at the right of the given width.

Signature

text.rjust(width, fillchar=' ')

Parameters

NameMeans
widththe total length wanted
fillcharwhat to pad with

Returns

A new string.

Example

Python
print("ab".rjust(6, ".") + "|")
print("ab".ljust(6, ".") + "|")
print("ab".center(6, ".") + "|")

Output

....ab|
ab....|
..ab..|

See also