>>> print 'there are {0:10} students and {1:10} teachers'.format(scnt, tcnt)
there are 100 students and 20 teachers
Run Code Online (Sandbox Code Playgroud)
什么是代码,以便输出成为:
there are 100 students and 20 teachers
Run Code Online (Sandbox Code Playgroud)
谢谢.
Eli*_*ght 18
print 'there are {0:<10} students and {1:<10} teachers'.format(scnt, tcnt)
Run Code Online (Sandbox Code Playgroud)
当旧%操作符-用于对齐时,新format方法使用<和>