Python string Method - rjust()

https‮w//:‬ww.theitroad.com

The rjust() method is a built-in string method in Python that returns a right-justified version of a string. The method adds padding to the left side of the string to make it a specified width.

The syntax for using rjust() method is as follows:

string.rjust(width, fillchar)

Here, string is the original string, width is the total width of the resulting string (including the original string), and fillchar is the character to use for padding (optional). If fillchar is not specified, the method uses a space character (" ").

The method returns a new string that is right-justified and padded with the specified character.

Here's an example of using the rjust() method:

string = "Hello"
justified_string = string.rjust(10, "*")
print(justified_string)

Output:

*****Hello

In the example above, the rjust() method was used to create a new string that is right-justified with a width of 10 and padded with the asterisk character ("*"). The resulting string is stored in the variable justified_string. Note that the original string "Hello" was added to the right side of the padding characters.