format specifier

The instructions after a colon inside a replacement field, such as .2f for two decimal places, that control how a value is shown.

In more detail

Common forms are .2f for a float with two decimals, , for thousands separators and >10 to right-align in ten characters. They change only the text shown; the value itself is not rounded. The same specifiers work in format(), str.format and f-strings.

Example

f"{2/3:.2f}"   # "0.67"

Related terms

Taught in

References

Certification courses