Python输出格式化
1. 类似于C语言,用%d、%s、%r
t = eval(input())
H = t // 3600
T = 3600*H
M = (t - T) // 60
S = t - T - 60*M
print("%d:%d:%d" % (H,M,S))
2. 用逗号隔开
Code:
n = 100000000
E2 - B2 = 14.4099702835083
print("test2(", n, ") costs ", E2 - B2, "s")
Out:
test2( 100000000 ) costs 14.4099702835083 s
但这种输出,屏幕上打印出来每个逗号之间有间隔
第三种方法解决
3. 把输出的数用str()函数格式化成字符串
Code:
n = 100000000
E2 - B2 = 14.4099702835083
print("test2("+ str(n) +") costs " + str(E2 - B2) + "s")
Out:
test2(100000000) costs 14.4099702835083s