Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: printf-style library/stdtype improvements #16741

Merged
merged 11 commits into from
Mar 31, 2024
17 changes: 10 additions & 7 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2276,15 +2276,18 @@ expression support in the :mod:`re` module).
alternatives provides their own trade-offs and benefits of simplicity,
flexibility, and/or extensibility.

String objects have one unique built-in operation: the ``%`` operator (modulo).
This is also known as the string *formatting* or *interpolation* operator.
Given ``format % values`` (where *format* is a string), ``%`` conversion
specifications in *format* are replaced with zero or more elements of *values*.
The effect is similar to using the :c:func:`sprintf` in the C language.
The % operator (modulo) can also be used for string formatting. Given ``'string'
% values``, instances of ``%`` in ``string`` are replaced with zero or more
elements of ``values``. This operation is commonly known as string
Copy link
Contributor

@slateny slateny Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to agree with Jelle's comment and also note that what's common can be somewhat subjective (for example, I'd search with the query string formatting instead of string interpolation, despite the wikipedia page). Would you be interested in updating the PR to address the review?

interpolation. The effect is similar to using the :c:func:`sprintf` in the C
language. For example::

If *format* requires a single argument, *values* may be a single non-tuple
>>> print('%s has %d quote types.' % ('Python', 2))
Python has 2 quote types.

If *string* requires a single argument, *values* may be a single non-tuple
object. [5]_ Otherwise, *values* must be a tuple with exactly the number of
items specified by the format string, or a single mapping object (for example, a
items specified by the string, or a single mapping object (for example, a
dictionary).

.. index::
Expand Down