str.format() -> how to left-justify

2020-02-28 05:38发布

>>> print 'there are {0:10} students and {1:10} teachers'.format(scnt, tcnt)
there are        100 students and         20 teachers

What would be the code so that the output became:

there are 100        students and 20         teachers

Thanks.

标签: python
1条回答
够拽才男人
2楼-- · 2020-02-28 06:01
print 'there are {0:<10} students and {1:<10} teachers'.format(scnt, tcnt)

While the old % operator uses - for alignment, the new format method uses < and >

查看更多
登录 后发表回答