Python’s format specification mini-language controls how a value is rendered
inside an f-string or str.format placeholder, written after a colon. This tool
decodes any spec you paste and lists every fill, align, sign, and type code.
How it works
The full grammar is:
[[fill]align][sign][#][0][width][grouping][.precision][type]
Each component is optional and parsed left to right:
- fill + align — a pad character and one of
<(left),>(right),^(center),=(pad after the sign). Fill requires an explicit align character. - sign —
+(always show),-(only negative, default), space (leading space for positives). - # — alternate form:
0b/0o/0xprefixes for integers, always-show decimal point for floats. - 0 — sign-aware zero padding (shorthand for
0=). - width — minimum field width.
- grouping —
,or_thousands separator. - .precision — digits after the decimal (floats) or max characters (strings).
- type —
d b o x f e g % setc.
The parser below splits your spec into exactly these parts and explains each.
Example
f"{1234.5:>+12,.2f}" # ' +1,234.50'
f"{255:#06x}" # '0x00ff'
f"{0.27:.1%}" # '27.0%'
Notes
- A leading
0enables sign-aware zero padding:f"{-7:05d}"->-0007. gswitches between fixed and scientific automatically;nis locale-aware.- F-strings and
str.formatshare this identical mini-language.