str.format() - >如何左倾

时间:2009-05-06 13:49:47

标签: python

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

代码是什么,以便输出成为:

there are 100        students and 20         teachers

感谢。

1 个答案:

答案 0 :(得分:17)

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

虽然旧%运算符使用-进行对齐,但新format方法使用<>