str.format() -> 如何左对齐
>>> 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 个回答
23
print 'there are {0:<10} students and {1:<10} teachers'.format(scnt, tcnt)
以前的 % 操作符用 - 来对齐文本,而新的 format 方法则使用 < 和 > 来进行对齐。