ID EN
Built-in Types

format

Python 3.11

Perform a string formatting operation. The string on which this method is called can contain literal text or replacement fields delimited by braces {}. Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument. Returns a copy of the string where each replacement field is replaced with the string value of the corresponding argument.

Syntax

PYTHON
str.format(*args, **kwargs)

Examples

Example 1
PYTHON
>>> "The sum of 1 + 2 is {0}".format(1+2)
'The sum of 1 + 2 is 3'

See Also

Format String Syntax int float complex decimal.Decimal