==[[Python 書式]]==[[Python]{{category ] | [[Category:書式}}]]
*http://docs.python.jp/2/library/string.html#string.Formatter
*http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/float.html
|-
|}
>>> >>> t = 173 >>> >>> w = 73 >>> >>> print 'あなたのBMIは、%0.1f です。' % (w / ((t/100.0)*2))
あなたのBMIは、21.1 です。
%(辞書のキー)コード
>>> >>> print '%(donuts)s、%(remon)s' % {'donuts':'ドはドーナツのド','remon':'レはレモンのレ'}
ドはドーナツのド、レはレモンのレ
===日付の書式設定===
>>> >>> time.strftime('%Y/%m/%d', time.localtime())
'2010/02/24'
>>> >>> datetime.today().strftime('%Y%m%d')
'20100224'
>>> >>> datetime.fromtimestamp(os.stat(r'/test.txt').st_ctime).strftime('%Y%m%d')
'20090824'
#例えば、 utcoffset() が timedelta(hours=-3, minutes=-30) を返すとしたら、 %z は文字列、 '-0330' で置き換えられます。
==[[Python3]]==
*https://pyformat.info/