1

Sorry if this question has been asked before, (Yes, I've checked) but I am writing a program for Python 3.6 and having difficulty trying to align the output of columns like so:

  0,     0,  0,   // - undefined - 
 10,    94,  2,   // -----   -----
 10,  9066,  2,   // ----- ! -----
 14, 11528,  2,   // ----- " -----
 24,  9370,  3,   // ----- # -----
 22,  9501,  3,   // ----- $ -----
 29,  9632,  4,   // ----- % -----
 24,  9894,  3,   // ----- & -----
  8, 11706,  1,   // ----- ' -----

Note that the numbers do not change the position of the commas. Currently, when I try to print out like this, the columns are thrown off.

Goodbye StackExchange
  • 21,680
  • 7
  • 47
  • 83
dark stuart
  • 123
  • 7

1 Answers1

0

You can either use the method .rjust to format each piece of the string. Or use for the .format method which allows you to replace fields in a string.

my_string = "10".rjust(3)+", "+"94".rjust(7)+", "+"2".rjust(4)

print(my_string)

#or

print("{0:3d}, {1:7d}, {2:4d}".format(10, 94, 2))
zelite
  • 1,303
  • 15
  • 34