Print fixed-width without tab
1 min readAug 31, 2019
When I want to print data in column view, I will use tab \t
to manage this problem. Problem is data length is not fix. If some data shorter than one tab and another data is longer than one tab. Tab solution will not work.
Just found new way to handle this problem using String format
for i in range(10):
print('{:<10}: {}'.format('*'*(i+1), 'row %s' % (i+1)))
From above code {:<10}
will reserved 10 space for text by writing text on left hand side. This is output of this code.
* : row 1
** : row 2
*** : row 3
**** : row 4
***** : row 5
****** : row 6
******* : row 7
******** : row 8
********* : row 9
**********: row 10
Happy coding :)