Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

input

Asks the user to type something, and returns it as a string.

Synopsis

input(prompt)

Description

input shows the prompt, then waits until the user presses Enter. It returns what they typed, without the Enter.

The result is always a string, even when the user types a number. Use int or float to turn it into a number.

Parameters

Name Meaning
prompt Text to show first. Optional. End it with a space so the answer does not touch it.

Return value

A str: what the user typed.

Example

name = input("What's your name? ")
print(f"hello, {name}")

It prints:

What's your name? David
hello, David

Common mistake

x = input("x: ")
y = input("y: ")
print(x + y)

It prints:

x: 1
y: 2
12

input returns strings, and + joins strings, so 1 and 2 make 12. Convert first: x = int(input("x: ")).

See also

int, float, print

input in the Python documentation

Last updated 2 weeks ago