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

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

ITMISS
浏览 1352回答 1
1回答

慕的地10843

“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的%一个意思表示格式化输出
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python