Home > Backend Development > Python Tutorial > Python 3 Input: Why is `raw_input()` Gone and How Do I Get User Input?

Python 3 Input: Why is `raw_input()` Gone and How Do I Get User Input?

Mary-Kate Olsen
Release: 2024-12-07 12:18:15
Original
260 people have browsed it

Python 3 Input: Why is `raw_input()` Gone and How Do I Get User Input?

Python 3: Farewell raw_input(), Welcome 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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template