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
- f-string Expressions
- Format Specifiers
- Format Mini-Language
- Template Strings and str.format