Python Academy · Lesson

Format Mini-Language

Pad, sign, and group numbers.

Lesson 3 of 413 steps

Format Mini-Language is a free Python Academy lesson on CoddyKit. This is lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, and your progress syncs across the web and the CoddyKit app. The Python Academy course includes 4 lessons in total.

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:+}')

Space for positives

A space flag leaves a blank where a sign would go on positive numbers, helping columns of mixed signs align.

for n in [3, -3, 12]:
    print(f'[{n: }]')

Zero padding

A 0 before the width pads with zeros instead of spaces, and it respects the sign position.

print(f'{7:05}')
print(f'{-7:05}')

Grouping with commas

The comma groups thousands. Combine it with width and zero-fill for fixed-width money columns.

amount = 48250
print(f'{amount:,}')
print(f'{amount:012,}')

Underscore grouping

An underscore can group digits too, and it works for binary and hex to group every four digits.

print(f'{1000000:_}')
print(f'{255:_b}')

The alternate form #

The # flag adds a base prefix for binary, octal, and hex: 0b, 0o, 0x.

n = 255
print(f'{n:#b}')
print(f'{n:#x}')

Combining sign and padding

Order matters: sign comes before zero/width. Here positive numbers show a plus and are zero-padded to width 6.

for n in [42, -42]:
    print(f'{n:+06}')

Money formatting

Putting it together, you can produce currency-style output with grouping and two decimals.

total = 1234567.5
print(f'$ {total:,.2f}')

Fill plus align plus sign

You can stack a fill character, alignment, and sign all in one spec for highly controlled output.

print(f'{99:*>+8}')
print(f'{-99:*>+8}')

Formatting with format()

The built-in format(value, spec) function applies the same mini-language without needing an f-string, useful when the spec is computed.

print(format(3.14159, '.2f'))
print(format(255, '#x'))

Quick Check

Which flag forces a leading plus sign on positive numbers?

Recap: Format Mini-Language

You learned the spec grammar pieces:

  • Sign flags: + always show, space leaves room for positives.
  • 0 zero-pads, , and _ group digits.
  • # adds 0b/0o/0x prefixes.
  • format(value, spec) applies the same rules without an f-string.
print(f'{1234.5:+012,.2f}')
Free to start

Learn Python with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
76
Lessons
320

Frequently Asked Questions

Is the “Format Mini-Language” lesson free?

Yes — the full text of “Format Mini-Language” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO. The Python Academy course includes 4 lessons in total.

What will I learn in “Format Mini-Language”?

Pad, sign, and group numbers. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Format Mini-Language” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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