如果你想格式化字節字符串,你得先使用標準的文本字符串,然后將其編碼為字節字符串。比如:>>> '{: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的%一個意思表示格式化輸出
添加回答
舉報
0/150
提交
取消