The input() Function in Python
Python's input() function pauses a program, waits for the user to type something, and returns it as a string — even if it looks like a number. Convert it with int() or float() before doing math.
Every program you have written so far is one-way — it outputs things but never asks the user for anything. Python's input() function changes that: it pauses the program, waits for the user to type something, then hands you back exactly what they typed.
This page covers how input() works, why everything it returns is a string even when the user types a number, and the classic bug that trips beginners up. Pair it with Data Types in Python for why the string-vs-number distinction matters here.
What you will learn
By the end you can:
- Use
input()to pause a program and read what the user types - Add a prompt so the user knows what to type
- Explain why
input()always returns a string - Convert input to a number with
int()orfloat()when you need to do math - Recognize the
ValueErrorthat happens with unexpected input
Reading a value from the user
Call input() with no arguments and Python waits silently until the user types something and presses Enter:
text = input()
# waits, then returns exactly what the user typedUsually you want to tell the user what you are asking for. Pass a string to input() and Python shows it as a prompt before waiting:
name = input("What is your name?\n")
# shows the prompt first, then waitsThe \n at the end is a newline character — it moves the cursor to the next line before the user starts typing, which just looks cleaner.
input() always returns a string
This is the detail that catches almost everyone: no matter what the user types — even if it looks like a number — input() hands it back as a string. If you want to do maths with it, you have to convert it first.
speed = input("Enter your speed: ")
speed = int(speed)
# converts the string '60' into the number 60Or more concisely, on one line — convert right where you read it:
speed = int(input("Enter your speed: "))When conversion fails
If the user types something unexpected — letters when you asked for a number — int() raises a ValueError:
speed = int(input("Enter your speed: "))
# user types "fast"
# ValueError: invalid literal for int() with base 10: 'fast'Handling that kind of error properly (so the program does not just crash) belongs to a later topic on exceptions — for now, just know it can happen and why.
Common mistakes
- Trying to add or subtract straight from
input()without converting first - Forgetting the prompt string, leaving users staring at a blank, silent program
- Using
int()on input that might contain a decimal point (usefloat()instead) - Assuming
input()validates anything — it accepts whatever the user types, valid or not
Why this matters
input() is the first real bridge between your program and a human. Almost every interactive script — calculators, quizzes, command-line tools — starts here. Getting the string-to-number conversion habit right early saves you from a whole category of "why won't this add up" bugs later.
Common questions
What does the input() function do in Python?
input() pauses program execution, waits for the user to type something and press Enter, then returns exactly what they typed as a string.
Does input() return a string or a number in Python?
input() always returns a string, even if the user types digits. To use it as a number, convert it explicitly with int() or float().
How do you convert input() to an integer in Python?
Wrap the call: age = int(input('Enter your age: ')). This reads the string from input() and converts it to an int in one line.
Why does input() cause a ValueError in Python?
A ValueError happens when you try to convert input() to a number (with int() or float()) but the user typed something that is not a valid number, like letters.
How do you add a prompt message to input() in Python?
Pass a string as the argument, like input('Enter your name: '). Python displays that text before pausing to wait for the user's response.
Explore
Related topics
Keep going — these sit next to this concept in a real learning path.
Data Types in Python
Why input() returning a string matters for the type you actually need.
Types, Values, and Errors in Python
More on how type() and conversions work.
Variables in Python
Storing what input() gives you back for later use.
Interactive Mode vs Script Mode in Python
How input() behaves the same way in both modes.
Strings in Python
Indexing, slicing, immutability, and string methods.
Lists in Python
Mutability, list methods, map/filter/reduce, and the aliasing trap.
Type Casting in Python
Implicit vs explicit conversion between data types.
Python course hub
All free Python explainers and the path into Agentic practice.