Rjust() Method Of Str Class

Method Name:

rjust

 

Method Signature:

rjust(width[, fillchar])

 

Method Overview:

  • The method rjust() returns a new string that is right justified within a string of width 'w'.

 

  • If the width is less than or equal to the length of the string, then the original string is returned.

 

  • If fillchar parameter is not specified then whitespace is assume to be the fill character.

 

Example:

sampleString    = "1000"

rightJustified  = sampleString.rjust(15)

 

print(rightJustified)

 

sampleString    = "1,000,000"

rightJustified  = sampleString.rjust(15)

 

print(rightJustified)

 

Output:

           1000

      1,000,000


Copyright 2019 © pythontic.com