DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

raw_input in Python: Python 3 Equivalent, Examples, and Migration Guide

Python 3’s equivalent of Python 2 raw_input() is input(). Learn how the two Python 2 input functions differed and how to convert responses safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to migrate code that uses raw_input()

  1. Confirm which interpreter runs the code. raw_input is a Python 2 name, not a Python 3 built-in. A NameError for raw_input in Python 3 usually means the code still uses the old name.
  2. Replace simple Python 2 raw_input() calls with input(). Keep the result as text unless the application requires another type.
  3. Convert deliberately where needed. Use a fitting parser, such as int() for an integer or float() for a decimal number, and handle invalid input if the program needs to recover.
  4. 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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.