我一直在通过以下方式打印我的程序的一些输出:
a=[1,2,3]
b=[10,20,30]
c=[101,201,301]
d=[1010,2010,3010]
results = {'a':a,'b':b,'c':c,'d':d}
print str("First result: ").center(20), str("Second result: ").center(20), str("Third result: ").center(20), str("Fourth result: ").rjust(20)
print
for i in xrange(len(results)):
print repr(float("{0:.2f}".format(results['a'][i]))).center(20),\
repr(float("{0:.2f}".format(results['b'][i]))).center(20),\
repr(float("{0:.2f}".format(results['c'][i]))).center(20),\
repr(float("{0:.2f}".format(results['d'][i]))).center(20)
这给出了以下很好的输出:
First result: Second result: Third result: Fourth result:
1.0 10.0 101.0 1010.0
2.0 20.0 201.0 2010.0
3.0 30.0 301.0 3010.0
但是现在假设我有许多未定义的结果,我怎么能写出同样的输出呢?
谢谢。