why does this unpacking work

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Oct 20 22:37:39 CEST 2006


In <%ba_g.133$1n3.3373 at news.tufts.edu>, John Salerno wrote:

> 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"))

Uhm, you mean::

 pair = (("California","San Francisco"),)

Note the extra comma to make that "a tuple in a tuple".

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list