Py3.3 unicode literal and input()

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Jun 18 04:28:11 EDT 2012


On Mon, Jun 18, 2012 at 1:19 AM, jmfauth <wxjmfauth at gmail.com> wrote:
> What is input() supposed to return?
>
>>>> u'a' == 'a'
> True
>>>>
>>>> r1 = input(':')
> :a
>>>> r2 = input(':')
> :u'a'
>>>> r1 == r2
> False
>>>> type(r1), len(r1)
> (<class 'str'>, 1)
>>>> type(r2), len(r2)
> (<class 'str'>, 4)
>>>>
>
> ---
>
> sys.argv?
>
> jmf

Python 3 made several backwards-incompatible changes over Python 2.
First of all, input() in Python 3 is equivalent to raw_input() in
Python 2. It always returns a string. If you want the equivalent of
Python 2's input(), eval the result. Second, Python 3 is now unicode
by default. The "str" class is a unicode string. There is a separate
bytes class, denoted by b"", for byte strings. The u prefix is only
there to make it easier to port a codebase from Python 2 to Python 3.
It doesn't actually do anything.



More information about the Python-list mailing list