Python rjust() method returns the right-justified string and fill the remaining spaces with specified fillchar.
The syntax of the method is: str.rjust(width[, fillchar])
We’ll be covering the following topics in this tutorial:
String rjust() Parameters
The rjust() method takes two parameters:
• width: width of the string provided. If the width is shorter than or equal to the string length, the original string would be restored.
• fillchar (Optional) : This is an optional parameter. These characters must be padded along the string.
Return value from String rjust()
The rjust() function returns a new string and substitutes the given fill_char to the original string’s left.
Below is the python program to demonstrate the rjust() function:
str = "The Best Learning Resource for Online Education"; print (str.rjust(50, '#'))
When we run above the program, the outcome is as follows:
###The Best Learning Resource for Online Education
Right justify string of minimum width
# example string str = 'Online Education' width = 25 # print right justified string print(str.rjust(width))
When we run above the program, the outcome is as follows:
Online Education
Below are several other functions that we can use to work with string in Python 3