3
在Python的Format Specification Mini-Language的閱讀,python字符串格式中的冒號是什麼意思?
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" | "%"
語法真的搞糊塗了。
例如,如果我想INT轉換爲二進制表示 我能做到這一點
"{0:b}".format(100)
"{:b}".format(100) # but this is fine too, so what dose the 0 do?
我知道b
代表在規範type
一部分,但我想不通的角色0
和:
,他們在做什麼?
請參閱https://pyformat.info/ – bigbounty