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 ?
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.
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.
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.
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.
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()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With