为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

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

1 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

“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的%一个意思表示格式化输出


查看完整回答
反对 回复 2018-09-05
  • 1 回答
  • 0 关注
  • 1351 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信