Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

raw_input("") has been eliminated from python 3.2

Tags:

I have tried a lot to run raw_input("") on the python console but that gives an error. Moreover I watch some videos that might have been made on old python. so input("") is the only method and why raw_input("") is discarded in the new version is there any reason ?

like image 878
Chitrank Dixit Avatar asked Jun 04 '12 17:06

Chitrank Dixit


People also ask

Does raw_input work in Python 3?

Python raw_input not workingRaw_input is not working in Python 3 version you can use the input() function instead of raw_input(). The input function has the same functionality to take input from the user. If you are using the raw_input() function then install the previous version of Python that is python 2.7.

What is raw_input () in Python give an example?

a = input() will take the user input and put it in the correct type. Eg: if user types 5 then the value in a is integer 5. a = raw_input() will take the user input and put it as a string. Eg: if user types 5 then the value in a is string '5' and not an integer.

What's 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.

Does input work in Python 2?

In Python 2, you have a built-in function raw_input() , whereas in Python 3, you have input() . The program will resume once the user presses the ENTER or RETURN key. Look at this example to get input from the keyboard using Python 2 in the interactive mode.


1 Answers

raw_input() was renamed to input() in Python v3.x

The old input() is gone, but you can emulate it with eval(input())

What's new in Python 3 will mention this (and more):

PEP 3111: raw_input() was renamed to input(). That is, the new input() function reads a line from sys.stdin and returns it with the trailing newline stripped. It raises EOFError if the input is terminated prematurely. To get the old behavior of input(), use eval(input()).

like image 192
Levon Avatar answered Sep 22 '22 05:09

Levon