Skip to content

Incorrect prompt strings in The Python Tutorial #122944

@Flyagin

Description

@Flyagin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasy

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions