Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

python text string alignment


May 10, 2021 Python2


Table of contents


python string alignment

Scene:

String alignment

python provides an easy way to align strings

  >>> print("abc".center (30,'-'))  
  -------------abc--------------                         
  >>> print("abc".ljust (30)+'|')  
  abc                           |  
  >>> print("abc".rjust (30))  
                             abc  
  >>>   

They are center, ljust, rjust

The three methods are spaces by default, or they can be filled with other characters