What's the difference between raw_input() and input() in python3.x?


Question

What is the difference between raw_input() and input() in python3.x ?

1
335
11/24/2012 2:34:36 PM

Accepted Answer

The difference is that raw_input() does not exist in Python 3.x, while input() does. Actually, the old raw_input() has been renamed to input(), and the old input() is gone, but can easily be simulated by using eval(input()). (Remember that eval() is evil. try to use safer ways of parsing your input if possible.)

392
1/10/2019 5:46:01 PM

In Python 2, raw_input() returns a string, and input() tries to run the input as a Python expression.

Since getting a string was almost always what you wanted, Python 3 does that with input(). As Sven says, if you ever want the old behaviour, eval(input()) works.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon