unpacking lists (there's more than one way to do it!)

Emile van Sebille emile at fenx.com
Tue Jan 15 22:28:40 EST 2002


"Roy Smith" <roy at panix.com> wrote in message
news:roy-1049EA.20421115012002 at news1.panix.com...
> All of the following seem to have the same effect:
>
> x, y = list
> (x, y) = list
> [x, y] = list
>
> Is there any reason to prefer one over the other?  FWIW, I
tend to write
> the last because I think it looks cleaner.


Anyone care to comment as to whether this means they do the same
thing?


>>> compile("(a,b) = a","","exec") == compile("a,b =
a","","exec")
1
>>> compile("[a,b] = a","","exec") == compile("a,b =
a","","exec")
1


Sure-seems-that-way-to-me-ly y'rs,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list