summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorAdorilson Bezerra <adorilson@gmail.com>2020-05-28 01:34:01 (GMT)
committerGitHub <noreply@github.com>2020-05-28 01:34:01 (GMT)
commiteaca2aa117d663acf8160a0b4543ee2c7006fcc7 (patch)
treeb0c2699e4b8c517d909a0161696d861fde9c1f4d /Doc/tutorial
parent56853d8ec6ed89bf5a9b81c3781a4df46ac391d3 (diff)
downloadcpython-eaca2aa117d663acf8160a0b4543ee2c7006fcc7.zip
cpython-eaca2aa117d663acf8160a0b4543ee2c7006fcc7.tar.gz
cpython-eaca2aa117d663acf8160a0b4543ee2c7006fcc7.tar.bz2
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 <aeros167@gmail.com>
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/inputoutput.rst10
1 files changed, 5 insertions, 5 deletions
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index a404f4b..366a532 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -172,7 +172,7 @@ Positional and keyword arguments can be arbitrarily combined::
If you have a really long format string that you don't want to split up, it
would be nice if you could reference the variables to be formatted by name
instead of by position. This can be done by simply passing the dict and using
-square brackets ``'[]'`` to access the keys ::
+square brackets ``'[]'`` to access the keys. ::
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
>>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; '
@@ -257,10 +257,10 @@ left with zeros. It understands about plus and minus signs::
Old string formatting
---------------------
-The ``%`` operator can also be used for string formatting. It interprets the
-left argument much like a :c:func:`sprintf`\ -style format string to be applied
-to the right argument, and returns the string resulting from this formatting
-operation. For example::
+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. For example::
>>> import math
>>> print('The value of pi is approximately %5.3f.' % math.pi)