Justify lines in python


How to Justify lines in python.
Want to align string center or left or right ?
ljust, center, rjust takes two parameter length of the output string and padding char.
Padding char is optional and default val is “ ”.



Examples.
  • rjust
     >>> a.rjust(40, "_")
     '___________________________________heloo'
     >>> a.rjust(40)
      heloo”

  • ljust
     >>> a.ljust(40, "_")
     'heloo___________________________________'
     >>> a.ljust(40)
     heloo '”


  • center
     >>> a.center(40, "_")
     '_________________heloo__________________'
     >>> a.center(40)
     heloo ”