@@ -992,18 +992,47 @@ are always available. They are listed here in alphabetical order.
992992.. function :: input()
993993 input(prompt, /)
994994
995- If the *prompt * argument is present, it is written to standard output without
996- a trailing newline. The function then reads a line from input, converts it
997- to a string (stripping a trailing newline), and returns that. When EOF is
998- read, :exc: `EOFError ` is raised. Example::
995+ Prompt the user for input, and return the answer as a string.
996+ For example::
999997
1000- >>> s = input('--> ') # doctest: +SKIP
1001- --> Monty Python's Flying Circus
998+ >>> s = input('What is your favorite color? ') # doctest: +SKIP
999+ What is your favorite color? Yellow
10021000 >>> s # doctest: +SKIP
1003- "Monty Python's Flying Circus"
1001+ 'Yellow'
10041002
1005- If the :mod: `readline ` module was loaded, then :func: `input ` will use it
1006- to provide elaborate line editing and history features.
1003+ >>> command = input('--> ') # doctest: +SKIP
1004+ --> cut the green wire
1005+ >>> command # doctest: +SKIP
1006+ 'cut the green wire'
1007+
1008+ .. admonition :: CPython implementation detail
1009+
1010+ By default, if the *prompt * argument is present, it is written to
1011+ standard output without a trailing space or newline.
1012+ The function then reads a line from input, converts it
1013+ to a string (stripping a trailing newline), and returns that.
1014+ When EOF is read, :exc: `EOFError ` is raised.
1015+
1016+ If this exact behavior is required, implement it explicitly instead
1017+ of calling :func: `!input `::
1018+
1019+ print(prompt, end='', flush=True)
1020+ sys.stdin.readline().strip('\n')
1021+
1022+ If the standard output is not interactive, then standard error
1023+ will be used for the prompt instead.
1024+
1025+ If the :mod: `readline ` module was loaded, then :func: `input ` will instead
1026+ use it to provide elaborate line editing and history features.
1027+ The may be used to
1028+ provide similar functionality.
1029+
1030+ Systems that lack standard input/output streams, or have different ways
1031+ of asking the user, often set :mod: `builtins.input <builtins> `,
1032+ or the C pointer :c:data: `PyOS_ReadlineFunctionPointer `, to a
1033+ more appropriate function.
1034+ For example, a framework for desktop applications could override
1035+ ``input `` to display a dialog.
10071036
10081037 .. audit-event :: builtins.input prompt input
10091038
@@ -1015,6 +1044,11 @@ are always available. They are listed here in alphabetical order.
10151044 Raises an :ref: `auditing event <auditing >` ``builtins.input/result ``
10161045 with the result after successfully reading input.
10171046
1047+ .. tip ::
1048+
1049+ Including a trailing space in *prompt *, as in the examples above,
1050+ often makes the result more pleasing.
1051+
10181052
10191053.. class :: int(number=0, /)
10201054 int(string, /, base=10)
0 commit comments