Built-in Functions and Types
input()
Read a line of text from standard input. An optional prompt is displayed without adding a newline. The returned string omits the trailing line ending; numeric conversion and validation are separate operations. End-of-file raises EOFError. Interactive input may be unavailable in automated evaluators.
Formal Syntax & Structure
python syntaxpython
input(prompt, /) # prompt optionalParameters & Attributes
| Name | Type | Description |
|---|---|---|
| prompt | object | Optional prompt displayed before reading; positional only. |
Return Value
str
One line of text, without its terminating newline.
Working Example
Example Snippetpython
# Controlled local stdin fixture; no real user input needed.from io import StringIOimport sysoriginal = sys.stdintry: sys.stdin = StringIO("42\n") answer = input("Quantity: ") print(int(answer) * 2)finally: sys.stdin = original