why does this unpacking work

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Oct 21 16:12:55 EDT 2006


John Salerno a écrit :
> johnzenger at gmail.com wrote:
> 
>> It's just sequence unpacking.  Did you know that this works?:
>>
>> pair = ("California","San Francisco")
>> state, city = pair
>> print city
>> # 'San Francisco'
>> print state
>> # 'California'
> 
> 
> Yes, I understand that. What confused me was if it had been written like 
> this:
> 
> pair = (("California","San Francisco"))


Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on 
linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> (("California","San Francisco")) == ("California","San Francisco")
True
pair = "California","San Francisco"
 >>> pair
('California', 'San Francisco')
 >>> t = 1,
 >>> t
(1,)
 >>> t = 1, 2
 >>> t
(1, 2)
 >>>

HTH






More information about the Python-list mailing list