Python Format String Reference

Decode any Python format spec and look up every fill, align, sign and type code

Interactive reference for Python's format specification mini-language used by f-strings and str.format — paste a spec like :>10.2f to decode its fill, align, sign, width, precision, and type, plus a full code table.

What is Python's format specification mini-language?

It is the small grammar that controls how a value is rendered inside an f-string replacement field or str.format placeholder, written after a colon. The full form is [[fill]align][sign][#][0][width][grouping][.precision][type]. For example f'{x:>+08.2f}' right-aligns, forces a sign, zero-pads to width 8 with two decimals as a fixed-point float.

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/0x prefixes 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).
  • typed b o x f e g % s etc.

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 0 enables sign-aware zero padding: f"{-7:05d}" -> -0007.
  • g switches between fixed and scientific automatically; n is locale-aware.
  • F-strings and str.format share this identical mini-language.