Python String - rjust() Method
The Python rjust() method returns the string with whitespaces added at the start of the string until its length reaches the specified length. This method has a optional parameter which can be used to specify a character to fill the missing space (default is whitespace).
Syntax
string.rjust(length, character)
Parameters
length |
Required. specify length of string after filling with specified character. |
character |
Optional. specify character to fill the missing space. default value is whitespace. |
Return Value
Returns the string with whitespaces added at the start of the given string until its length reaches the specified length.
Example:
In the example below, rjust() method returns the string with the specified character added at the start of the string until its length reaches the specified length.
MyString = "Learn Python" print(MyString.rjust(20)) MyString = "Learn Python" print(MyString.rjust(20, "#"))
The output of the above code will be:
Learn Python ########Learn Python
❮ Python String Methods