The rjust() method in Python string is responsible for returning the string right which is justified in a string of the length width. Padding is done making use of the specified fillchar where space is the default one. The original string is therefore returned when width is less than len(s).
Here is the syntax for rjust() method:
- width − This width represents the string length in total after padding.
- fillchar − This refers to the filler character where space is default.
This method in Python string returns the string which is right justified within a string of length width. Padding is done making use of the specified fillchar where default is the space. The original string is thus returned in case width is lesser than len(s).
The example below shows the usage of rjust() method.
str = "this is string example....wow!!!";
print str.rjust(50, '0')
When the above program is run, it produces the following result:
000000000000000000this is string example....wow!!!
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.