default tuple unpacking?

Peter Hansen peter at
Tue Sep 3 23:44:28 EDT 2002

Huaiyu Zhu wrote:
> It is often very convenient to have default arguments such as
>     def func(a, b, *c): ...
> Is there a way to use this in statements too?  Examples:
>     a, (b, *c), *d = e

Presumably d would end up as () if there was nothing to put there,
just as in the default argument syntax for functions?

>     for a, *b in c: ...
>     return a, *b

These are all very readable to me, having learned to grok
the basic "def func(a, b, *c):" syntax.  I'd be in favour
of seeing this added, as the first idiom above is something
I've needed fairly often.

Is there an analog for the **x syntax?  I hope nobody
suggests that having

 >>> d = { 'a' : 5, 'b' : 7 }
 >>> **d

should be equivalent to

 >>> a = 5
 >>> b = 7



More information about the Python-list mailing list