0Pricing
Python Academy · Lesson

Format Mini-Language

Pad, sign, and group numbers.

The Format Mini-Language

Python's Format Specification Mini-Language is the grammar that lives after the colon. Its full form is: [fill][align][sign][#][0][width][,][.precision][type].

This lesson focuses on signs, padding, and grouping.

print(f'{42:08.2f}')

Always show the sign

The + sign flag forces a leading + on positive numbers, while negatives always keep their -.

print(f'{5:+}')
print(f'{-5:+}')

All lessons in this course

  1. f-string Expressions
  2. Format Specifiers
  3. Format Mini-Language
  4. Template Strings and str.format
← Back to Python Academy