Skip to content
Related Articles

Related Articles

Python String rjust() Method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 05 Oct, 2021

Python String rjust() method returns a new string of a given length after substituting a given character on the left side of the original string.


string.rjust(length, fillchar)


  • length: length of the modified string. If length is less than or equal to the length of the original string then original string is returned.
  • fillchar: (optional) characters which needs to be padded. If it’s not provided, space is taken as a default argument.

Return Value:

Returns a new string of given length after substituting a given character in left side of original string.

Example 1


# Python program to demonstrate working of
# rjust()
string = 'geeks'
length = 8
# If no fill character is provided, space
# is used as fill character



Example 2


# example string
string = 'geeks'
length = 8
fillchar = '*'
print(string.rjust(length, fillchar))



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!