I have integer numbers in the range of 0 up until (including) 100. I want to convert them to strings of a fixed length of 3 with space padding and alignment to the right.
I've tried to use the following format string, but it adds another space for three digit numbers, which makes them length 4 instead of 3.
fmt = lambda x: "{: 3d}".format(x)
[fmt(99), fmt(100)] # produces [' 99', ' 100'] instead of [' 99', '100']
Interestingly, it works as expected when zero-padding is used:
fmt = lambda x: "{:03d}".format(x)
[fmt(99), fmt(100)] # produces ['099', '100'] as expected
Why is this? How can I fix this?
Do I really need to convert to string first?
fmt = lambda x: "{:>3s}".format(str(x))
[fmt(99), fmt(100)] # produces [' 99', '100'] as expected