格式化输出浮点数(float)
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
#浮点数的格式化,精度、度和
格式化输出字符串(string)
#precise = 3
print"%.3s "%("jcodeer")
#precise = 4print"%.*s"%(4,"jcodeer")
#width = 10,precise = 3print"%10.3s"%("jcodeer")
#输出结果:#jco#jcod# jco
网友评论