Python String rjust() Method

Right justifies a string, left-padding with the specified character or substring to the specified width.

Syntax

Python
string.rjust(length, character = " ")

Parameters

ParameterDescription
length Required. The length of the final string. If length is less than the length of the supplied.
character Optional. The character to use for padding the string. Default is a space (" ")

Example

Python
print('ABC'.rjust(20, '-'))

Output

-----------------ABC