Skip to content

Commit d9c8911

Browse files
bpo-34712: Fix style in examples in "Input and Output" (GH-9361)
A couple of fixes here to make this more PEP-8: * Avoid multiple statements on one line with `;` statement separator -- this is very rare in Python and is "generally discouraged" in PEP 8 (and if used, per PEP 8 there shouldn't be a space before the `;`) * Add output for the first "Formatted String Literals" example. (Side note: are the doctests for this being run? If so, why didn't it fail?) * Avoid space before `!r`. I have generally not seen spaces before the `!`, and this also matches the style used in the docs here: https://docs.python.org/3/library/string.htmlGH-format-string-syntax https://bugs.python.org/issue34712 (cherry picked from commit 3705b98) Co-authored-by: Ben Hoyt <[email protected]>
1 parent 95cc3ee commit d9c8911

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Doc/tutorial/inputoutput.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ printing space-separated values. There are several ways to format output.
2929

3030
::
3131

32-
>>> year = 2016 ; event = 'Referendum'
32+
>>> year = 2016
33+
>>> event = 'Referendum'
3334
>>> f'Results of the {year} {event}'
3435
'Results of the 2016 Referendum'
3536

@@ -40,8 +41,9 @@ printing space-separated values. There are several ways to format output.
4041

4142
::
4243

43-
>>> yes_votes = 42_572_654 ; no_votes = 43_132_495
44-
>>> percentage = yes_votes/(yes_votes+no_votes)
44+
>>> yes_votes = 42_572_654
45+
>>> no_votes = 43_132_495
46+
>>> percentage = yes_votes / (yes_votes + no_votes)
4547
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
4648
' 42572654 YES votes 49.67%'
4749

@@ -108,6 +110,7 @@ three places after the decimal::
108110

109111
>>> import math
110112
>>> print(f'The value of pi is approximately {math.pi:.3f}.')
113+
The value of pi is approximately 3.142.
111114

112115
Passing an integer after the ``':'`` will cause that field to be a minimum
113116
number of characters wide. This is useful for making columns line up. ::
@@ -127,7 +130,7 @@ applies :func:`repr`::
127130
>>> animals = 'eels'
128131
>>> print(f'My hovercraft is full of {animals}.')
129132
My hovercraft is full of eels.
130-
>>> print(f'My hovercraft is full of {animals !r}.')
133+
>>> print(f'My hovercraft is full of {animals!r}.')
131134
My hovercraft is full of 'eels'.
132135

133136
For a reference on these format specifications, see

0 commit comments

Comments
 (0)