Python - String rjust() Method


Advertisements

The string rjust() method is used to return 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.

Example:

In the below example, rjust() method is used to return 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, "#"))

Output

        Learn Python

########Learn Python

String Methods
Advertisements