p0015 内置函数

format()

1
2
3
4
5
6
7
8
9
printcipal = 0.1234
year = 2018
print(format(year,"3d"),format(printcipal, "0.2f"))
print("{0:3d} {1:0.2f}".format(year,printcipal))
print("%3d %0.2f" % (year,printcipal))