Python String rjust() Method
rjust() returns a new string with the original string right-justified and padded with spaces to the length width. If the specified length is less than the length of the string, the original string is returned.
Python String rjust() Syntax
rjust() method syntax.
str.rjust(width[, fillchar])
Python String rjust() Parameters
- width – Specifies the total length of the string after filling the specified characters.
- fillchar – the character to be filled, default is space.
Python String rjust() Return Value
Returns a new string with the original string right-aligned and padded to the length width with spaces. If the specified length is less than the length of the string, the original string is returned.
Python String rjust() Example#1
The following example demonstrates the use of the rjust() function.
#!/usr/bin/python3
str = "this is string example from api demos.com....good examples!"
print (str.rjust(50, '*'))
Output: