On this page
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
- Delegates to
value.__format__(spec): Uses the exact same format mini-language as f-strings (f"{x:,.2f}").
REPL Inspect
help(format)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/ascii
- tuts/python3/__builtins__/bin
- tuts/python3/__builtins__/chr
- tuts/python3/__builtins__/float
- tuts/python3/__builtins__/frozenset
- tuts/python3/__builtins__/hex
- tuts/python3/__builtins__/oct
- tuts/python3/__builtins__/ord
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ascii Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bin Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/chr Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/float Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/frozenset Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/hex Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/oct Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ord links to this page; shared tags: #builtins