Home / Python / Reference / String methods

Python string rjust() method

Pad a string on the left so it is right-aligned in a fixed width.

Syntax

str.rjust(width, fillchar=" ")

Parameters

widthtotal width
fillcharthe padding character

Return value

str

Example

Code

for n in [7, 42, 1234]:
    print(str(n).rjust(6))

Output

     7
    42
  1234

Related

Learn it step by step in the free lesson Strings, with exercises that check your answers.