How to Read What the User Types in Python with input
A terminal program talks to its user with input(): it prints a question, waits for the user to type an answer and press Enter, and gives you that answer as text. This guide asks for a name and greets it, with real output from Python 3.15.2.
Syntax
<answer> = input(<prompt>)
| Part | What it means |
|---|---|
<prompt> | Optional text printed before the cursor, such as "What is your name? " |
<answer> | What the user typed, as a string, without the Enter at the end |
Python's documentation: "If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
name = input("What is your name? ")
print(f"Hello, {name}!")

The prompt ends with a space, so the answer doesn't touch the question mark.
Step 2: Run It
uv run python ask_name.py
Type Sam and press Enter:
What is your name? Sam
Hello, Sam!

The program stopped at the prompt until the answer arrived, then carried on with it in name.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Doing arithmetic with the answer, as in input("Age: ") + 1 | TypeError: can only concatenate str (not "int") to str: the answer is always a string | Convert it first: int(input("Age: ")) + 1 |
| Leaving out the space at the end of the prompt | The answer is glued to the question | End the prompt with a space |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
EOFError | Input ended before a line was read: Ctrl+D (Ctrl+Z then Enter on Windows), or a pipe with no more data | Catch EOFError where the program reads input |
| The program seems frozen | It's waiting at input() for an answer | Type an answer and press Enter |
FAQ
How do I get a number?
Wrap the call in int() or float(): int(input("Age: ")). An answer that isn't a number then raises ValueError.
Can I read several answers?
Call input() once per answer, or in a loop until the user types a word that ends it.
Conclusion
input("What is your name? ") printed the question, waited for Sam and Enter, and returned "Sam", which the next line put into a greeting.
Additional Resources
- input() — prompts, return values and
EOFError.
