On 12/12/2013 14:56, Amit Saha wrote:
On Fri, Dec 13, 2013 at 12:45 AM, <stephen.bou...@gmail.com> wrote:
Can someone explain? Thanks.
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
x = input()
Hello there
print(x)
Hello there
In Python 3, input() considers an input as a string and returns the
input as a string. This is the behavior of raw_input() in Python 2.
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
x = input()
Hello there
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
Hello there
^
SyntaxError: unexpected EOF while parsing
In Python 2, input() expects valid Python as it's input. If you
provide your input as 'Hello there' (a Python string), it won't
complain.
HTH,
Amit.
I much prefer Chris Angelico's response "The input() function in Python
2.x is a very dangerous one - it's equivalent to eval(input()) in Python 3."
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
--
https://mail.python.org/mailman/listinfo/python-list