Reputation: 687
I am trying to have all the values indented and at the same level whilst printing the integers and strings specified below. I am trying to have the space equidistant throughout. How would I be able to do that?
print('Consecutive monthly {} results: {}\tIndexes: {} - {}'.format('positive',14,'2019-04-01 00:00:00','2020-06-01 00:00:00'))
print('Consecutive monthly {} results: {}\tIndexes: {} - {}'.format('negative',2,'2018-02-01 00:00:00','2020-06-01 00:00:00'))
Output
Consecutive monthly positive results: 14 Indexes: 2019-04-01 00:00:00 - 2020-06-01 00:00:00
Consecutive monthly negative results: 2 Indexes: 2018-02-01 00:00:00 - 2018-03-01 00:00:00
Expected Output:
Consecutive monthly positive results: 14 Indexes: 2019-04-01 00:00:00 - 2020-06-01 00:00:00
Consecutive monthly negative results: 2 Indexes: 2018-02-01 00:00:00 - 2018-03-01 00:00:00
Upvotes: 0
Views: 59
Reputation: 425
You can specify the format for decimal number like this.
print('Consecutive monthly {} results: {:<2d}\tIndexes: {} - {}'.format('positive',14,'2019-04-01 00:00:00','2020-06-01 00:00:00'))
print('Consecutive monthly {} results: {:<2d}\tIndexes: {} - {}'.format('negative',2,'2018-02-01 00:00:00','2020-06-01 00:00:00'))
The ':<2d' in the format string specifies the number to be left justified, and space(in characters) it should take for it.
Upvotes: 1