python:格式化输出整数

import math

#default

print "PI = %f" % math.pi

#width = 10,precise = 3,align = left

print "PI = %10.3f" % math.pi

#width = 10,precise = 3,align = rigth

print "PI = %-10.3f" % math.pi

#前面填充字符

print "PI = %06d" % int(math.pi)

 

#输出结果

#PI = 3.141593

#PI =      3.142

#PI = 3.142

#PI = 000003

#浮点数的格式化,精度、度和

你可能感兴趣的:(python)