python一共有两种格式化输出语法,
一种是类似于C语言printf的方式,称为 Formatting Expression
>>> '%s %d-%d' % ('hello', 7, 1)
'hello 7-1'
另一种是类似于C#的方式,称为String Formatting Method Calls
>>> '{0} {1}:{2}'.format('hello', '1', '7')
'hello 1:7'
第一种方式可以指定浮点数的精度,例如
>>> '%.3f' % 1.234567869
'1.235'