Skip to content

Commit bcf135a

Browse files
committed
gh-142108: document conversion rules for printf-style formatting
Also add a reference to documentation for old formatting.
1 parent 3e2c557 commit bcf135a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,6 +2944,12 @@ The conversion types are:
29442944
| | character in the result. | |
29452945
+------------+-----------------------------------------------------+-------+
29462946

2947+
For a general non-string Python object ``obj``, numeric conversion types
2948+
attempt to format values, converted first to built-in :class:`float` (by
2949+
``float(obj)``, for floating-point formats) and :class:`int` (by
2950+
``operator.index(obj)`` for ``'o'``, ``'x'``, ``'X'`` or ``'c'`` formats, or by
2951+
``int(obj)`` for other integer formats) types.
2952+
29472953
Notes:
29482954

29492955
(1)

Doc/library/string.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ Format examples
645645
^^^^^^^^^^^^^^^
646646

647647
This section contains examples of the :meth:`str.format` syntax and
648-
comparison with the old ``%``-formatting.
648+
comparison with the old :ref:`printf-style formatting <old-string-formatting>`.
649649

650650
In most of the cases the syntax is similar to the old ``%``-formatting, with the
651651
addition of the ``{}`` and with ``:`` used instead of ``%``.

0 commit comments

Comments
 (0)