Home >Backend Development >Python Tutorial >Python 3 Input: Why is `raw_input()` Gone and How Do I Get User Input?
In Python 2, raw_input() was used to read user input. However, when transitioning to Python 3, developers encounter the error:
NameError: name 'raw_input' is not defined
This error arises because raw_input() underwent a transformation in Python 3. To maintain compatibility with Python 2, Python 3 introduced input(), which seamlessly replaced raw_input().
As stated in the Python documentation under What's New In Python 3.0:
"The raw_input() function is now called input(), and input() now does what raw_input() did in Python 2.7: it returns the input as a string, regardless of its content."
Therefore, to utilize user input functionality in Python 3, simply replace raw_input() with input(). This substitution ensures seamless migration from Python 2 to Python 3.
The above is the detailed content of Python 3 Input: Why is `raw_input()` Gone and How Do I Get User Input?. For more information, please follow other related articles on the PHP Chinese website!