Python string alignment rjust method
Python String Alignment: rjust Method
Description
The rjust() method returns a string right-aligned within a string of length width. The fill character is the specified fillchar (defaults to a space). If width is less than len(s), the original string is returned.
Syntax
The syntax of the rjust() method is as follows:
var.rjust(width[, fillchar])
Parameters
- width − This is the total length of the string after padding.
- fillchar − This is the fill character, which defaults to a space.
Return Value
This method returns a string, right-aligned within a string of length width. The fill character is the specified fillchar (a space by default). If width is less than len(s), the original string is returned.
Example
The following example demonstrates the use of the rjust() method.
var = "This Is String Example....WOW!!!"
var1 = var.rjust(40, '*')
print ("original string:", var)
print ("Right justified string:", var1)
When you run this program, it will produce the following output:
original string: This Is String Example....WOW!!!
Right justified string: ********This Is String Example....WOW!!!