Returns right justified string
Usage
The rjust()
method returns right-justified string of length width. Padding is done using the specified fillchar (default is an ASCII space).
The original string is returned as it is, if width is less than or equal to string length.
Syntax
string.rjust(width,fillchar)
Parameter | Condition | Description |
width | Required | The length of the string |
fillchar | Optional | A character you want to use as a fill character. Default is an ASCII space. |
Basic Example
# Align text right
S = 'Right'
x = S.rjust(12)
print(x)
# Prints Right
Specify a Fill Character
By default the string is padded with whitespace (ASCII space). You can modify that by specifying a fill character.
# * as a fill character
S = 'Right'
x = S.rjust(12, '*')
print(x)
# Prints *******Right
Equivalent Method
You can achieve the same result by using format() method.
S = 'Right'
x = '{:>12}'.format(S)
print(x)
# Prints Right