From bcf135a431f19194009a837a7ddf1f2acb21fb99 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 1 Dec 2025 09:17:07 +0300 Subject: [PATCH] gh-142108: document conversion rules for printf-style formatting Also add a reference to documentation for old formatting. --- Doc/library/stdtypes.rst | 6 ++++++ Doc/library/string.rst | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 8b896011734df5..51574fcbcb9863 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2944,6 +2944,12 @@ The conversion types are: | | character in the result. | | +------------+-----------------------------------------------------+-------+ +For a general non-string Python object ``obj``, numeric conversion types +attempt to format values, converted first to built-in :class:`float` (by +``float(obj)``, for floating-point formats) and :class:`int` (by +``operator.index(obj)`` for ``'o'``, ``'x'``, ``'X'`` or ``'c'`` formats, or by +``int(obj)`` for other integer formats) types. + Notes: (1) diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 58c836c7382330..d25705ba0ed8d1 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -645,7 +645,7 @@ Format examples ^^^^^^^^^^^^^^^ This section contains examples of the :meth:`str.format` syntax and -comparison with the old ``%``-formatting. +comparison with the old :ref:`printf-style formatting `. In most of the cases the syntax is similar to the old ``%``-formatting, with the addition of the ``{}`` and with ``:`` used instead of ``%``.