Skip to content

Commit

Permalink
Doc: printf-style library/stdtype improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
adorilson committed Oct 13, 2019
1 parent 27b33fb commit cbd73ec
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2156,15 +2156,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
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 002 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

0 comments on commit cbd73ec

Please sign in to comment.