Python Function Reference

input

Read a line that the user types on the keyboard.

Python 3.13
input([prompt])
  • [ ]optional part
prompt
A hint printed before the input, without a trailing newline.
strOptional

Return value

A string with the entered text; convert it with int or float to get a number.

Examples

Input with a prompt

Python 3.13
name = input("Enter your name: ")
print(f"Hello, {name}!")

The result is always a string

Python 3.13
answer = input("Enter a number: ")
print(type(answer))
<class 'str'>

Reading a number

Python 3.13
age = int(input("Your age: "))
print("Next year you will be", age + 1)

Details

The trailing newline is not included in the result. In a regular program, EOFError is raised when the input has ended (EOF). On this page and in the lessons, code runs in the browser, which has no input stream: before the run, the sandbox asks for one value for each place in the code like input("…") with a string prompt and hands these values to the input calls in order. Once the values run out, for example on repeated calls in a loop, input returns an empty string.

See also

Where to learn