リンク
ちゃんと調べるときは
http://www.python.jp/doc/release/
Wiki内検索
最近更新したページ
最新コメント
文字コードの判定 by awesome things!
正規表現 by awesome things!
辞書 by stunning seo guys
文字列の16進変換 by check it out
文字コードの変換 by check this out
デバッガ by check this out
サブプロセス by watch for this
文字コードの判定 by watch for this
サニタイジング by check this out
タグ

文字列フォーマット

昔ながらの%での指定と、format関数の使用例

>>>
>>> scalar = 111111.234567
>>> list = [ 1, 'あいうえお' ]
>>> dict = {'key': 'value', 2: 1002 }
>>>
>>> "{ } scalar: %.3f  array[0]: %05d  hash['key']: %s" % (scalar, list[0], dict['key'])
"{ } scalar: 111111.235  array[0]: 00001  hash['key']: value"
>>>
>>> "{{ }} scalar: {0:.3f}  array[0]: {1[0]:05d}  hash['key']: {2[key]:s}".format(scalar, list, dict)
"{ } scalar: 111111.235  array[0]: 00001  hash['key']: value"
>>>

6.6.2. 文字列フォーマット操作:
http://www.python.jp/doc/release/library/stdtypes....

7.1. ファンシーな出力の書式化:
http://www.python.jp/doc/release/tutorial/inputout...
2011年01月28日(金) 12:45:49 Modified by hebi_




スマートフォン版で見る