>>> str(123)
'123'
>>> str(1.23)
'1.23'
>>> 'a month has %d days'%30
'a month has 30 days'
>>> 'a big month has %d days,a small month has %d days'%(31,30)
'a big month has 31 days,a small month has 30 days'
>>> 'a big month has %10d days'%30
'a big month has 30 days'
注:用%後面的替換前面的%d
注:%d中間的10說明長度為10,has後面已經有一個空格了。
>>> 'the number is %.1f'%1.23
'the number is 1.2'
>>> 'the number is %10.1f'%1.23
'the number is 1.2'
注意:is後面已經有一個空格了。