str.rjust in Python

Python Methods and Functions

Positions the specified string to the right, padding it to the left to the specified length with the specified character.

str.rjust (width [, fillchar])

-> str

width - Desired minimum length of the resulting string.

fillchar - The character to expand the string. The default is a space. 


The original line is not truncated, even if it contains more characters than the desired length parameter.

  '' .rjust (3, 'w') # www 
' 1'.rjust (4, 'w') # www1
' 1'.rjust (0, 'w') # 1
'1'.rjust (4) #' 1'

Note

The antonym of the function that positions the string to the left is str.ljust () .


Notes

Use str.center () .


Notes

When you need to pad the string with zeros on the left, use zfill/"> str.zfill () .





Get Solution for free from DataCamp guru