書式付文字列 formatted string
> x=1.0
> y=2
> "x=%6.2f, y=%6.2f" % (x, y)
'x= 1.00, y= 2.00'
> "%4.4d"%x
'0001'
古い方法らしいが,ダブルまたはシングルクオテーションで囲う中に,書式を書き,%で変数とつなげる.複数の変数には( )を使う
An old method for python 2.x, but still works.
> "%4.4d"%x
'0001'
> x=1.0
> y=2
> "x=%6.2f, y=%6.2f" % (x, y)
'x= 1.00, y= 2.00'