开发者

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

开发者 https://www.devze.com 2022-12-16 02:11 出处:网络
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:

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

精彩评论

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

关注公众号