How to get a space-padded string with the original string right-justified in Python?

PythonServer Side ProgrammingProgramming

We can use the method rjust() which returns the string right justified in a string of length equal to 'width' which is the string length in total after padding. Padding is done using the specified fillchar (default is a space). The original string is returned if width is less than len(s). For example:

>>> '15'.rjust(10)
'        15'
>>> 'Yes'.rjust(2)
>>> >>> 'raj'.rjust(12)
'         raj'
Updated on 30-Sep-2019 06:42:40