首页 新闻 赞助 找找看

python 格式化字符串 ,想问下{:10s}这{}里面的“:” 起到什么作用

0
悬赏园豆:5 [已解决问题] 解决于 2018-06-04 17:37

如果你想格式化字节字符串,你得先使用标准的文本字符串,然后将其编码为字节
字符串。比如:
>>> '{:10s} {:10d} {:10.2f}'.format('ACME', 100, 490.1).encode('ascii')
b'ACME 100 490.10'
>>>
想问下{:10s}这{}里面的“:” 起到什么作用

筱筱的春天的主页 筱筱的春天 | 菜鸟二级 | 园豆:295
提问于:2018-06-03 08:19
< >
分享
最佳答案
0

“In most of the cases the syntax is similar to the old %-formatting, with the addition of the {} and with : used instead of %. For example, '%03.2f' can be translated to '{:03.2f}'"

:应该是代替了%,跟C语言的printf的%一个意思表示格式化输出

收获园豆:5
MartinLwx | 菜鸟二级 |园豆:211 | 2018-06-03 22:44

谢谢你的答案,对我很有帮助

筱筱的春天 | 园豆:295 (菜鸟二级) | 2018-06-04 17:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册