Python spacing and aligning strings

后端 未结 6 1316
失恋的感觉
失恋的感觉 2020-12-04 08:42

I am trying to add spacing to align text in between two strings vars without using \" \" to do so

Trying to get the text to look like this, with the second co

6条回答
  •  不思量自难忘°
    2020-12-04 09:25

    Try %*s and %-*s and prefix each string with the column width:

    >>> print "Location: %-*s  Revision: %s" % (20,"10-10-10-10","1")
    Location: 10-10-10-10           Revision: 1
    >>> print "District: %-*s  Date: %s" % (20,"Tower","May 16, 2012")
    District: Tower                 Date: May 16, 2012
    

提交回复
热议问题