Skip to content

Commit 3608c8c

Browse files
committed
gh-106318: Add example for str.format()
1 parent ed4cc6f commit 3608c8c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,10 +1927,14 @@ expression support in the :mod:`re` module).
19271927
``{}``. Each replacement field contains either the numeric index of a
19281928
positional argument, or the name of a keyword argument. Returns a copy of
19291929
the string where each replacement field is replaced with the string value of
1930-
the corresponding argument.
1930+
the corresponding argument. For example:
1931+
1932+
.. doctest::
19311933

19321934
>>> "The sum of 1 + 2 is {0}".format(1+2)
19331935
'The sum of 1 + 2 is 3'
1936+
>>> "{1} expects the {0} Inquisition!".format("Spanish", "Nobody")
1937+
'Nobody expects the Spanish Inquisition!'
19341938

19351939
See :ref:`formatstrings` for a description of the various formatting options
19361940
that can be specified in format strings.

0 commit comments

Comments
 (0)