On this page
  1. format
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

format

Prev: float | Up: __builtins__ | Next: frozenset
Rel: ascii, bin, chr, hex, oct
Ref: docs.python.org — format
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import format

Overview & Signature

format(value, format_spec='', /)

Return type(value).format(value, format_spec) Many built-in types implement format_spec according to the Format Specification Mini-language. See help('FORMATTING').

Usage

assert format(1234567.89, ",.2f") == "1,234,567.89"
assert format(0.256, ".1%") == "25.6%"

Gotchas

REPL Inspect

help(format)

Linked from

Related notes