Python2.6+ 增加了str.format函数,用来代替原有的’%’操作符。它使用比’%’更加直观、灵活。下面详细介绍一下它的使用方法。
下面是使用’%’的例子:
""
"PI is %f..." % 3.14159 # => 'PI is 3.141590...'
"%d + %d = %d" % (5, 6, 5+6) # => '5 + 6 = 11'
"The usage of %(language)s" % {"language": "python"} # => 'The usage of python'
格式很像C语言的printf是不是?由于’%’是一个操作符,只能在左