PROJET AUTOBLOG


Shaarli - Les discussions de Shaarli

Archivé

Site original : Shaarli - Les discussions de Shaarli du 23/07/2013

⇐ retour index

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

mercredi 15 juillet 2015 à 13:00

« Python 2.7.3 (default, Mar 13 2014, 11:03:55)
>>> username = input("Username : ")
Username : guigui
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<string>", line 1, in <module>
NameError: name 'guigui' is not defined
>>> nb = input("Un nombre ? ")
Un nombre ? 42
>>> »

« 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. [...] raw_input() does not exist in Python 3.x »
(Permalink)