PyDocs

Nav

Python Runtime Services

str.format

builtins

method of str
  • str.format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}').
Changed in 3.7
  • 3.7: When formatting a number with the n type, the function sets temporarily the LC_CTYPE locale to the LC_NUMERIC locale in some cases.
1 Example
>>> "The sum of 1 + 2 is {0}".format(1+2)
'The sum of 1 + 2 is 3'
>>> "The sum of {a} + {b} is {answer}".format(answer=1+2, a=1, b=2)
'The sum of 1 + 2 is 3'
>>> "{1} expects the {0} Inquisition!".format("Spanish", "Nobody")
'Nobody expects the Spanish Inquisition!'
from the Python docs
See Also
No see-alsos for builtins/str.format
0 Notes
No notes for str.format