第一种是格式化的
strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))
import math#defaultprint "PI = %f" % math.pi#width = 10,precise = 3,align = leftprint "PI = %10.3f" % math.pi#width = 10,precise = 3,align = rigthprint "PI = %-10.3f" % math.pi#前面填充字符print "PI = %06d" % int(math.pi) #输出结果#PI = 3.141593#PI = 3.142#PI = 3.142#PI = 000003#浮点数的格式化,精度、度和
refer to:
另外一种是用字符串的格式化
print('We are the {} who say "{}!"'.format('knights', 'Ni'))
refer to: