格式化这个的好方法是什么?

Mic*_*key 0 python printing format

这是代码:

print "Unsorted \t Bubble \t Insertion"

for x, y, z in zip(List, arr_bs, arr_is):
    print '{0:2d}\t\t{1:3d}\t\t{2:4d}'.format(x, y, z)

print "Seconds: \t %f \t %f" % (time_bs, time_is)
Run Code Online (Sandbox Code Playgroud)

这是输出:

Unsorted     Bubble      Insertion
43        5        5
88       18       18
57       24       24
86       37       37
81       37       37
18       38       38
 5       43       43
24       57       57
76       76       76
37       81       81
37       86       86
38       88       88
Seconds:     0.000091    0.000042
Run Code Online (Sandbox Code Playgroud)

啊,无法让输出看起来像在终端中那样,但你明白了.我是python的新手,有更多pythonic方式来格式化这些打印语句吗?

欢迎提出意见,谢谢.

Shr*_*rey 8

print "%-25s %-15s %15s" % ("STACK","OVERFLOW","PYTHON")
Run Code Online (Sandbox Code Playgroud)

上面的打印行可以在您的代码中使用.您只需要用变量替换字符串常量.