Python3里的字符串格式化功能很强大,新手看到下面的形式化描述可能会比较害怕:
format_spec ::= [[fill]align][sign][#][0][width][grouping_option][.precision][type]
fill ::= <any character>
align ::= "<" | ">" | "=" | "^"
sign ::= "+" | "-" | " "
width ::= digit+
grouping_option ::= "_" | ","
precision ::= digit+
type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
我先挑出比较常用的,画了一张图,每种用法都配了几个常用的例子:

当然,还有一张更全的。
