input() in Python: read and convert what the user types
input() is your program's ear. It pauses, captures a line the user types, and returns it — always as a string, which is the detail that trips people up.
The big idea
input() returns whatever the user types as a str, so numeric input must be converted with int() or float() before math.
See it in code
input() is your program's ear. It pauses, captures the line the user types, and returns it. Here we read a name and welcome the player:
print("Enter your name:")
name = input()
print("Welcome,", name)Enter your name: Welcome, Neo
The program waited at input(), then used the captured line. It returns whatever was typed as a string — which matters the moment you want a number.
Here's the catch that trips people up: input() always returns a string, even when the user types digits. Watch what + does to it:
print("Enter a number:")
text = input()
print("You typed:", text)
print("Twice that:", text + text)Enter a number: You typed: 7 Twice that: 77
text + text glued "7" to "7" into "77" — string joining, not addition. To do math, you must convert the string to a number first.
Now the fix. A tool asks for a bet amount. input() reads the line as text — "50", not 50 — so we wrap it in int(...) right away, and the math works:
print("Enter your bet amount:")
amount = int(input())
print("Doubling your bet to", amount * 2)Enter your bet amount: Doubling your bet to 100
input() returned the string "50"; int(...) turned it into the number 50, so amount * 2 gave 100. Without the conversion, "50" * 2 would have produced "5050" — string repetition, not doubling.
Reading and converting external input is universal — command-line tools, config files, web form fields, API responses all arrive as text you must parse. The pattern is always: read the raw string, validate it, convert it, then use it.
Try it yourself
Ask for two numbers and print their sum, converting each with int(). Then wrap the conversion in a try / except so a non-number reply doesn't crash the program.
The common mistake
Doing math on the raw string. int(input()) + 10 works, but input() + 10 raises a TypeError because you can't add text and a number. Always convert numeric input the moment you read it.
What it unlocks
Handling input relies on data types and conversions, and pairs with try / except to survive bad input.