开发者

Python: How do you format a string % number with str.format()

How can I format a string like this

"%01.2f" % pr"%01.2f" % some_number

but using the str.format() style? I'm used to this:

'{0} {1}'.format(somev开发者_C百科alue1, somevalue2)

Is there a way to use that function style vs the old % style, and still achieve this decimal formatting?


It would be like {0:01.2f}, I believe. See http://docs.python.org/library/string.html#format-string-syntax.

Edit: added in your zero-padding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜