2009-05-06 33 views
8
>>> print 'there are {0:10} students and {1:10} teachers'.format(scnt, tcnt) 
there are  100 students and   20 teachers 

會是什麼代碼,使輸出成爲:str.format() - >如何左對齊

there are 100  students and 20   teachers 

感謝。

回答

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

雖然老%操作員使用-進行調準,新format方法使用<>