Format strings (str.format() or format(), extended to f-strings and t-strings) are based off of format specification mini-language which is made up of replacement fields where values are substituted in.
- Replacement fields are surrounded with
{}({}itself is escaped with{{}}), and begin with a field name, optionally followed by a conversion field (preceded by!), and a format specification (preceded by:). - A field name consists of an argument name, which is a number or an identifier (specifying the kwarg), and infinitely nested attribute accesses (e.g.
.a.b.c), indexing ([0][1][2]), or a combination of the two (e.g.[0].a[1].b[2].c).- If a format string consists only of numbers in sequence (excluding attribute access and indexing), they could be omitted.
- A conversion field is used if the
str()value (!s), or arepr()value (!r) is needed. - A format specification is used to format the value in a specific manner; its syntax is s