python中冒号的含义是什么;s字符串格式?

python中冒号的含义是什么;s字符串格式?,python,Python,在阅读Python的 我知道b代表规范中的类型部分,但我无法确定0和:的角色,他们在做什么 您只查看格式规范的语法,指定了完整语法: 零指定可选的字段\ u name,在本例中,该字段对应于要在传递的参数元组中格式化的项的索引;它是可选的,因此可以删除。请参阅 format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type] fill ::= <any character> align

在阅读Python的


我知道
b
代表规范中的
类型
部分,但我无法确定
0
的角色,他们在做什么

您只查看
格式规范的语法,指定了完整语法:

零指定可选的
字段\ u name
,在本例中,该字段对应于要在传递的参数元组中格式化的项的索引;它是可选的,因此可以删除。

请参阅
format_spec ::=  [[fill]align][sign][#][0][width][,][.precision][type]  
fill        ::=  <any character>  
align       ::=  "<" | ">" | "=" | "^"  
sign        ::=  "+" | "-" | " "  
width       ::=  integer  
precision   ::=  integer  
type        ::=  "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"   
"{0:b}".format(100)
"{:b}".format(100) # but this is fine too, so what dose the 0 do?
replacement_field ::=  "{" [field_name] ["!" conversion] [":" format_spec] "}"
field_name        ::=  arg_name ("." attribute_name | "[" element_index "]")*
arg_name          ::=  [identifier | integer]
attribute_name    ::=  identifier
element_index     ::=  integer | index_string
index_string      ::=  <any source character except "]"> +
conversion        ::=  "r" | "s"
format_spec       ::=  <described in the next section>
>>> "{0:b}".format(100)
'1100100'