Py3.3 unicode literal and input()
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Jun 18 06:08:02 EDT 2012
On Mon, 18 Jun 2012 01:19:32 -0700, jmfauth wrote:
> What is input() supposed to return?
Whatever you type.
>>>> u'a' == 'a'
> True
This demonstrates that in Python 3.3, u'a' gives a string equal to 'a'.
>>>> r1 = input(':')
> :a
Since you typed the letter a, r1 is the string "a" (a single character).
>>>> r2 = input(':')
> :u'a'
Since you typed four characters, namely lowercase u, single quote,
lowercase a, single quote, r2 is the string "u'a'" (four characters).
>>>> r1 == r2
> False
>>>> type(r1), len(r1)
> (<class 'str'>, 1)
>>>> type(r2), len(r2)
> (<class 'str'>, 4)
If you call print(r1) and print(r2), that will show you what they hold.
If in doubt, calling print(repr(r1)) will show extra information about
the object.
> sys.argv?
What about it?
>
> jmf
More information about the Python-list
mailing list