Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between `raw_input()` and `input()` in Python 3?

What is the difference between raw_input() and input() in Python 3?

like image 754
pkumar Avatar asked Feb 06 '11 18:02

pkumar


People also ask

What is the difference between raw_input () and input () in Python?

Basically, the difference between raw_input and input is that the return type of raw_input is always string, while the return type of input need not be string only. Python will judge as to what data type will it fit the best. In case you have entered a number, it will take it as an integer.

What is raw_input () in Python?

Python raw_input function is used to get the values from the user. We call this function to tell the program to stop and wait for the user to input the values. It is a built-in function. The input function is used only in Python 2. x version.

What does input () do in Python 3?

Python 3 – input() function. In Python, we use input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function convert it into a string.

Why is raw_input not defined in Python?

The NameError: name 'raw_input' is not defined occurs when you try to call the raw_input() function using Python major version 3. You can only use raw_input() in Python 2. To solve this error, replace all instances of raw_input() with the input() function in your program.


1 Answers

The difference is that raw_input() does not exist in Python 3.x, while input() does. Actually, the old raw_input() has been renamed to input(), and the old input() is gone, but can easily be simulated by using eval(input()). (Remember that eval() is evil. Try to use safer ways of parsing your input if possible.)

like image 59
Sven Marnach Avatar answered Oct 06 '22 05:10

Sven Marnach