In Python 3, replace Python 2’s raw_input(prompt) with input(prompt). Both read a line and return it as text. The important migration trap is that Python 2’s separate input() evaluated the entered text as a Python expression; Python 3’s input() does not.
What did raw_input() do in Python 2?
Python 2.7’s raw_input([prompt]) displayed an optional prompt, read one line, removed its trailing newline, and returned the result as a string. It did not automatically convert a response such as 42 into a number. End-of-file raised EOFError. See the Python 2.7 built-in function reference.
What is the Python 3 equivalent?
Use Python 3’s built-in input(). It reads one line, returns a string with a trailing newline stripped, and raises EOFError when input ends. The prompt, if supplied, is displayed without a newline. The rename was specified in PEP 3111; the current behavior is documented in the Python 3.14 built-in function reference.
Read a response as text
Python 2:
name = raw_input("What is your name? ")
Python 3:
name = input("What is your name? ")
In Python 3, name is a string. Keep it as text if that is what your program needs.
#1 Best Overall
Convert a response to a number
Convert explicitly when the program needs a numeric value:
age = int(input("Age: "))
price = float(input("Price: "))
If the entered text cannot be parsed as the requested number, int() or float() raises ValueError. An interactive program can catch that exception and ask again rather than stopping.
Rank #2
Python 2 and Python 3 input behavior compared
| Behavior | Python 2.7 raw_input(prompt) |
Python 2.7 input(prompt) |
Python 3 input(prompt) |
|---|---|---|---|
| Reads a line | Yes | Yes, through raw_input() |
Yes |
| Return value | String | Evaluated Python expression result | String |
| Trailing newline | Removed | Removed by the underlying read | Removed |
| End of input | Raises EOFError |
Can propagate the read failure | Raises EOFError |
| Migration | Replace with Python 3 input() |
Inspect intended behavior; parse the input explicitly where possible | Convert text explicitly if another type is needed |
The Python 2 behaviors are documented in the Python 2.7 raw_input() reference and Python 2.7 input() reference. Python 3’s rename and changed behavior are also described in the Python 3.0 release notes.
Why Python 2 input() is a migration trap
In Python 2.7, input(prompt) was equivalent to eval(raw_input(prompt)): it read text and evaluated it as a Python expression. In Python 3, input() returns the text itself. For example, code that relied on Python 2 input() to receive a number should use int(input(...)) or float(input(...)) if that matches the expected format.
Free tools Windows power users keep installed
One-click scans. No signup required.
Do not blindly replace Python 2 input() with Python 3 input() and assume the result has the old type. Nor should eval(input()) be used as a routine fix: it preserves expression evaluation instead of parsing a specific expected value. Choose a conversion or parser that matches the data your program accepts.
How to migrate code that uses raw_input()
- Confirm which interpreter runs the code.
raw_inputis a Python 2 name, not a Python 3 built-in. ANameErrorforraw_inputin Python 3 usually means the code still uses the old name. - Replace simple Python 2
raw_input()calls withinput(). Keep the result as text unless the application requires another type. - Convert deliberately where needed. Use a fitting parser, such as
int()for an integer orfloat()for a decimal number, and handle invalid input if the program needs to recover. - Review every Python 2
input()call separately. Determine what expression values the old code expected, then replace that behavior with an appropriate explicit parser. A name-for-name substitution can change program behavior.
Python 2 reached end of life at the start of 2020, according to the Python 3.11 porting guide. The Python 3.11 2to3 documentation describes a fixer that changes raw_input() to input(), but also says lib2to3 was deprecated in Python 3.11 and removed in Python 3.13. That specific documentation therefore does not establish it as a universal tool for current Python versions.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




