0

I have this

    Partition 0 | 0 | 0 | 4
    Partition 1 | 4 | 4 | 4
    Partition 2 | 8 | 8 | 8
    Partition 3 | 16 | 16 | 16
    Partition 4 | 32 | 32 | 32

I want to do this

Partition 0 |  0 |  0 |  4
Partition 1 |  4 |  4 |  4
Partition 2 |  8 |  8 |  8
Partition 3 | 16 | 16 | 16
Partition 4 | 32 | 32 | 32

Below is my Python 3 code, summarized. Where a,b,c,d are appropriate ints.

for i in range(5)
    print(("Partition %d | %d | %d | %d") % (a, b, c, d))

Basically, I want that space in between | | to be always the same, no matter the digit.

Is there any way to achieve this simply using formatting perhaps? I can think of achieving this using string formatting and adding/subtracting spaces depending on the number of digits but that sounds way too complicated.

I tried searching, but I'm stil learning so I don't know what terms I need to use to describe my problem. If you could refer to me to a relevant link to read that will be great as well.

Leonard
  • 2,978
  • 6
  • 21
  • 42

0 Answers0