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

← All Python built-ins