如果你想格式化字节字符串,你得先使用标准的文本字符串,然后将其编码为字节字符串。比如:>>> '{:10s} {:10d} {:10.2f}'.format('ACME', 100, 490.1).encode('ascii')b'ACME 100 490.10'>>>想问下{:10s}这{}里面的“:” 起到什么作用
1 回答
![?](http://img1.sycdn.imooc.com/5333a1a90001c8d802000200-100-100.jpg)
慕的地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的%一个意思表示格式化输出
添加回答
举报
0/150
提交
取消