From cbd73ecf2b672606674b7d2214e0ec00f101a603 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 12 Oct 2019 23:18:08 -0300 Subject: [PATCH 1/8] Doc: printf-style library/stdtype improvements --- Doc/library/stdtypes.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index e8b3aba4b90976..b98245a42f1e95 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -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:: From f66508cde1112291bdd352318b57e91099a19e19 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Mon, 28 Oct 2019 13:16:30 -0300 Subject: [PATCH 2/8] [Doc]Fix example output in library/stdtypes --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index b98245a42f1e95..70c94fb3104559 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2163,7 +2163,7 @@ interpolation. The effect is similar to using the :c:func:`sprintf` in the C language. For example:: >>> print('%s has %d quote types.' % ('Python', 2)) - Python has 002 quote types. + 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 From 6abf90885e9b4ec16fdf347527ab9a222a9d798d Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 10 Jun 2023 15:25:34 +0100 Subject: [PATCH 3/8] Doc: some adjustments in printf-style library/stdtype --- Doc/library/stdtypes.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 2ffbe5c5146305..a1b8981abad9b8 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2330,10 +2330,10 @@ expression support in the :mod:`re` module). flexibility, and/or extensibility. 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:: +% values``, instances of ``%`` inside of the ``string`` starts a conversion +specifier, which will be 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:: >>> print('%s has %d quote types.' % ('Python', 2)) Python has 2 quote types. From f75ed9567ca3adbbccf32e957e00473d1a2bddf3 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 31 Mar 2024 19:09:29 +0100 Subject: [PATCH 4/8] Revert "Doc: some adjustments in printf-style library/stdtype" This reverts commit 6abf90885e9b4ec16fdf347527ab9a222a9d798d. --- Doc/library/stdtypes.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a1b8981abad9b8..2ffbe5c5146305 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2330,10 +2330,10 @@ expression support in the :mod:`re` module). flexibility, and/or extensibility. The % operator (modulo) can also be used for string formatting. Given ``'string' -% values``, instances of ``%`` inside of the ``string`` starts a conversion -specifier, which will be 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:: +% 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:: >>> print('%s has %d quote types.' % ('Python', 2)) Python has 2 quote types. From 70da987bc0aa37cc0c9324bba7683f1aa337b7d4 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 31 Mar 2024 19:10:15 +0100 Subject: [PATCH 5/8] Revert "[Doc]Fix example output in library/stdtypes" This reverts commit f66508cde1112291bdd352318b57e91099a19e19. --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 2ffbe5c5146305..bb09e04b60e424 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2336,7 +2336,7 @@ interpolation. The effect is similar to using the :c:func:`sprintf` in the C language. For example:: >>> print('%s has %d quote types.' % ('Python', 2)) - Python has 2 quote types. + 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 From 8369b4f13f4785594c0fd070b6bc76db835acae3 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 31 Mar 2024 19:10:30 +0100 Subject: [PATCH 6/8] Revert "Doc: printf-style library/stdtype improvements" This reverts commit cbd73ecf2b672606674b7d2214e0ec00f101a603. --- Doc/library/stdtypes.rst | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index bb09e04b60e424..0caa725f75e642 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2329,18 +2329,15 @@ expression support in the :mod:`re` module). alternatives provides their own trade-offs and benefits of simplicity, flexibility, and/or extensibility. -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:: - - >>> print('%s has %d quote types.' % ('Python', 2)) - Python has 002 quote types. +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. -If *string* requires a single argument, *values* may be a single non-tuple +If *format* 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 string, or a single mapping object (for example, a +items specified by the format string, or a single mapping object (for example, a dictionary). .. index:: From 640c8330c723eaf4bbf4f6ea3325658461ed8ee3 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 31 Mar 2024 19:22:39 +0100 Subject: [PATCH 7/8] [Doc] Add simpler example to % operator in stdtypes --- Doc/library/stdtypes.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 0caa725f75e642..ef9aee703374da 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2333,7 +2333,11 @@ 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 effect is similar to using the :c:func:`sprintf` in the C language. For +example:: + + >>> print('%s has %d quote types.' % ('Python', 2)) + Python has 2 quote types. If *format* requires a single argument, *values* may be a single non-tuple object. [5]_ Otherwise, *values* must be a tuple with exactly the number of From d43d3a502fa2829fa9a57072cc785241d166b948 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sun, 31 Mar 2024 22:11:18 +0100 Subject: [PATCH 8/8] [Doc] Add doctest directive to an example in stdtypes Co-authored-by: Erlend E. Aasland --- Doc/library/stdtypes.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ef9aee703374da..0725e2c03b5020 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2333,8 +2333,10 @@ 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. For -example:: +The effect is similar to using the :c:func:`sprintf` function in the C language. +For example: + +.. doctest:: >>> print('%s has %d quote types.' % ('Python', 2)) Python has 2 quote types.