👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
Python 3 has replaced Python 2’s raw_input ()
method with the input () method . If you try to use raw_input ()
in Python 3, you will encounter the error NameError: name ’raw_input’ undefined
.
In this guide, we will discuss what this error means and why you may encounter it. We’ll look at an example of this error, along with a solution, so you can learn how to fix it.
NameError: the name ’raw_input’ is not defined
The raw_input () in Python 2 collects input from a user. This input can be converted to any data type, such as a string, an integer, or a floating point number.
Consider this code:
username = raw_input ("Enter a username:")
We can use this code to collect a username from a user in Python 2.
Being able to collect a user’s data means that you can make your programs interactive. You don’t just have to define all the data in the program you will be using. You can ask a user to provide data.
In Python 3, many changes have been made to the Python language. Among them is raw_input ()
which has been renamed to input ()
. Both functions collect data from sys.stdin
(also called "standard input") and return this data to a program.