Open In App

input() vs raw_input() functions in Python

Last Updated : 17 Sep, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, both input() and raw_input() functions are used to take user input. But:

  • raw_input() exists only in Python 2.x.
  • input() exists in both Python 2.x and Python 3.x but they behave differently in each version.

Let’s break this down clearly with explanations and examples.

input() in Python 3.x

It is used to take input from user as a string. It waits for user to type something and press Enter, then returns that input as a string which can be stored or processed in program. 

Example:

Python
val1 = input("Enter the name: ")
print(type(val1))
print(val1)

val2 = input("Enter the number: ")
print(type(val2))

val2 = int(val2)
print(type(val2))
print(val2)

Output

Enter the name: python3
<class 'str'>
python3

Enter the number: 1997
<class 'str'>
<class 'int'>
1997

Explanation:

  • "python3" is stored in val1. Its type is string.
  • "1997" is stored in val2. Initially it is also a string.
  • Using int(val2) changes it into an integer.

input() in Python 2.x

In Python 2, things are a bit different:

  • input() tries to evaluate the input as code.
  • When enter a number, it will store it as a number automatically.
  • When enter text, you must put it inside quotes; otherwise, Python 2 will throw an error.

Example:

Python
val1 = input("Enter the name: ")
print(type(val1))
print(val1)

val2 = input("Enter the number: ")
print(type(val2))
print(val2)

Output

Enter the name: "python3"
<type 'str'>
python3

Enter the number: 1997
<type 'int'>
1997

Explanation:

  • If you type "python3" (with quotes), it is treated as a string.
  • If you type 1997 (without quotes), it is treated as an integer automatically.

raw_input()

The raw_input() function in Python 2 was designed to avoid confusion.

  • It always takes input as a string, just like input() in Python 3.
  • If you want the input in another type (e.g., integer), you need to explicitly convert it using int() or float().

Example:

Python
val1 = raw_input("Enter the name: ")
print(type(val1))
print(val1)

val2 = raw_input("Enter the number: ")
print(type(val2))   # String
val2 = int(val2)    # Convert to integer
print(type(val2))
print(val2)

Output

 Enter the name: python3
<type 'str'>
python3

Enter the number: 1997
<type 'str'>
<class 'int'>
1997

Explanation:

  • "python3" is stored as a string directly.
  • "1997" is also stored as a string, and later converted into an integer using int().

input() vs raw_input()

Let's see difference in tabular form:

Featureinput() (Python 2.x)raw_input() (Python 2.x)input() (Python 3.x)
AvailabilityPython 2 onlyPython 2 onlyPython 3 only
Return TypeEvaluates input (string, int, float, etc. depending on what you type)Always returns stringAlways returns string
Need for quotesYes, for stringsNo quotes neededNo quotes needed
Conversion neededNot always (auto-detects type)Yes (must convert manually)Yes (must convert manually)
StatusDeprecated in Python 3Deprecated in Python 3Actively used

Explore