Skip to content

Commit f5bd99b

Browse files
Improve IO tutorial's "Old string formatting" section (GH-16251)
* Use a more universal explanation of string interpolation rather than specifically referencing sprintf(), which depends on the reader having a C background. Co-authored-by: Kyle Stanley <[email protected]> (cherry picked from commit eaca2aa) Co-authored-by: Adorilson Bezerra <[email protected]>
1 parent 1c4dcaf commit f5bd99b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Doc/tutorial/inputoutput.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Positional and keyword arguments can be arbitrarily combined::
172172
If you have a really long format string that you don't want to split up, it
173173
would be nice if you could reference the variables to be formatted by name
174174
instead of by position. This can be done by simply passing the dict and using
175-
square brackets ``'[]'`` to access the keys ::
175+
square brackets ``'[]'`` to access the keys. ::
176176

177177
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
178178
>>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; '
@@ -257,10 +257,10 @@ left with zeros. It understands about plus and minus signs::
257257
Old string formatting
258258
---------------------
259259

260-
The ``%`` operator can also be used for string formatting. It interprets the
261-
left argument much like a :c:func:`sprintf`\ -style format string to be applied
262-
to the right argument, and returns the string resulting from this formatting
263-
operation. For example::
260+
The % operator (modulo) can also be used for string formatting. Given ``'string'
261+
% values``, instances of ``%`` in ``string`` are replaced with zero or more
262+
elements of ``values``. This operation is commonly known as string
263+
interpolation. For example::
264264

265265
>>> import math
266266
>>> print('The value of pi is approximately %5.3f.' % math.pi)

0 commit comments

Comments
 (0)