Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61723
| References | <2ba69b81-99f9-40d6-a337-afb2f892ecff@googlegroups.com> |
|---|---|
| From | Amit Saha <amitsaha.in@gmail.com> |
| Date | 2013-12-13 00:56 +1000 |
| Subject | Re: input() on python 2.7.5 vs 3.3.2 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3997.1386860214.18130.python-list@python.org> (permalink) |
On Fri, Dec 13, 2013 at 12:45 AM, <stephen.boulet@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. -- http://echorand.me
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
input() on python 2.7.5 vs 3.3.2 stephen.boulet@gmail.com - 2013-12-12 06:45 -0800 Re: input() on python 2.7.5 vs 3.3.2 Chris Angelico <rosuav@gmail.com> - 2013-12-13 01:53 +1100 Re: input() on python 2.7.5 vs 3.3.2 Amit Saha <amitsaha.in@gmail.com> - 2013-12-13 00:56 +1000 Re: input() on python 2.7.5 vs 3.3.2 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-12 15:04 +0000 Re: input() on python 2.7.5 vs 3.3.2 Chris Angelico <rosuav@gmail.com> - 2013-12-13 02:17 +1100
csiph-web