x, = y (???)
Duncan Booth
duncan.booth at invalid.invalid
Thu Jul 17 17:02:42 EDT 2008
kj <socyl at 987jk.com.invalid> wrote:
> I still don't get it. If we write
>
> y = 'Y'
> x, = y
>
> what's the difference now between x and y? And if there's no
> difference, what's the point of performing such "unpacking"?
None whatsoever when the string has only one character, but with 2
characters it becomes an obfuscated way of checking that there was only one
character:
>>> x, = 'a'
>>> x, = 'ab'
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
x, = 'ab'
ValueError: too many values to unpack
More information about the Python-list
mailing list