python / cpython

The Python programming language
https://www.python.org
Other
63.6k stars 30.47k forks source link

Incorrect prompt strings in The Python Tutorial #122944

Closed Flyagin closed 3 months ago

Flyagin commented 3 months ago

When one enters a string consisting exclusively of a comment [like "# this is a comment" (without quotes)], the next prompt string should be ">>>", and it actually is so in 14 places in 4 files in The Python Tutorial listed below. Yet in 9 other places in 4 files in The Python Tutorial, the next prompt string is "...". I think that it should be corrected. Of course, the "..." prompt string is suitable sometimes, but where? In compound statements, such as while, whereas comments do not belong to this category.

Wrong prompt strings ("...", after strings consisting exclusively of a comment)

introduction.rst

line 503

   >>> # Fibonacci series:
   ... # the sum of two elements defines the next

controlflow.rst

line 63

   >>> # Measure some strings:
   ... words = ['cat', 'window', 'defenestrate']

line 447

   >>> # Now call the function we just defined:
   ... fib(2000)

datastructures.rst

line 385

   >>> # Tuples may be nested:
   ... u = t, (1, 2, 3, 4, 5)

line 389

   >>> # Tuples are immutable:
   ... t[0] = 88888

line 394

   >>> # but they can contain mutable objects:
   ... v = ([1, 2, 3], [3, 2, 1])

line 467

   >>> # Demonstrate set operations on unique letters from two words
   ...

inputoutput.rst

line 89

   >>> # The repr() of a string adds string quotes and backslashes:
   ... hello = 'hello, world\n'

line 94

   >>> # The argument to repr() may be any Python object:
   ... repr((x, y, ('spam', 'eggs')))

Correct prompt strings (">>>", after strings consisting exclusively of a comment)

introduction.rst

line 219

   >>> # 3 times 'un', followed by 'ium'
   >>> 3 * 'un' + 'ium'

line 461

   >>> # replace some values
   >>> letters[2:5] = ['C', 'D', 'E']

line 465

   >>> # now remove them
   >>> letters[2:5] = []

line 469

   >>> # clear the list by replacing all the elements with an empty list
   >>> letters[:] = []

datastructures.rst

line 252

   >>> # create a new list with the values doubled
   >>> [x*2 for x in vec]

line 255

   >>> # filter the list to exclude negative numbers
   >>> [x for x in vec if x >= 0]

line 258

   >>> # apply a function to all the elements
   >>> [abs(x) for x in vec]

line 261

   >>> # call a method on each element
   >>> freshfruit = ['  banana', '  loganberry ', 'passion fruit  ']

line 265

   >>> # create a list of 2-tuples like (number, square)
   >>> [(x, x**2) for x in range(6)]

line 268

   >>> # the tuple must be parenthesized, otherwise an error is raised
   >>> [x, x**2 for x in range(6)]

line 274

   >>> # flatten a list using a listcomp with two 'for'
   >>> vec = [[1,2,3], [4,5,6], [7,8,9]]

inputoutput.rst

line 354

    >>> # We can check that the file has been automatically closed.
    >>> f.closed

stdlib.rst

line 218

   >>> # dates are easily constructed and formatted
   >>> from datetime import date

line 226

   >>> # dates support calendar arithmetic
   >>> birthday = date(1964, 7, 31)

Linked PRs

sobolevn commented 3 months ago

PR is welcome! 👍

terryjreedy commented 3 months ago

Thanks for the report and PR. I have no idea if the REPL ever continued with ... after top level comments, but it definitely does not do so now (3.12+), and docs for 3.x should match 3.x.

Flyagin commented 3 months ago

Thank you for replies!