io
input()
Reads a line from sys.stdin, strips the trailing newline, and returns it as a string. Optionally writes prompt to stdout first.
input(prompt='') Parameters
| Parameter | Purpose |
|---|---|
| prompt | Text written to stdout before reading input |
| returns | The line read as a str (newline stripped); EOFError at end-of-stream |
Examples
name = input('Name: ') Prompts then reads a line
n = int(input('n: ')) Converts input to int (raises ValueError on bad input)
try:
line = input()
except EOFError:
line = '' Handles piped EOF
Gotcha
Always returns str — convert with int()/float() when needed. Raises EOFError on end-of-stream (e.g. Ctrl-D or piped input).
Related built-ins
print()
Writes the given objects to a text stream, converting each with str() and joining with sep. Adds end (newline by default) after the last object.
open()
Opens a file and returns a file object. Default mode 'r' is text read; use 'rb'/'wb' for binary.
int()
Constructs an integer from a number or string. When x is a string, base selects the numeric base (0 auto-detects from prefix).