1

I have a question about formatting with Python. I want to print 2 columns with the following code, but as you can see, the numbers on the second column shift on the output. Is there something I can modify to have them line up to the left?

i = 0
print ("%s      %s" % ("Col1","Col2"))
while i <= 199:
    print ("%s              %.2f" % (i,i*2.2))
    i += 30

Output:

Col1           Col2
0              0.00
30              66.00
60              132.00
90              198.00
120              264.00
150              330.00
180              396.00
user2864740
  • 60,010
  • 15
  • 145
  • 220
user3648426
  • 227
  • 1
  • 4
  • 13
  • I do not agree that this question is precisely a duplicate. The old string formatting methods using %s is still valid. For example when setting up logging configuration. The other way of formatting a srting using str.format() is not given as examples for Python logging basicconfig, See "16.6.7. LogRecord attributes" https://docs.python.org/3/library/logging.html#logging.Logger.log – DevPlayer Mar 19 '15 at 17:10

0 Answers0