Default paranmeter for packed values
clp2 at rebertia.com
Mon Apr 19 01:46:10 CEST 2010
On Sun, Apr 18, 2010 at 4:23 PM, Xavier Ho <contact at xavierho.com> wrote:
> I ran into a strange problem today: why does Python not allow default
> paranmeters for packed arguments in a function def?
>>>> def test(a = 1, b = (2, 3)):
> ... print a, b
> 1 (2, 3)
>>>> def t(a, *b = (3, 4)):
> File "<input>", line 1
> def t(a, *b = (3, 4)):
> SyntaxError: invalid syntax
> What was the rationale behind this design?
It's not specific to default arguments:
*z = (1,2,3) #==>
File "<stdin>", line 1
*z = (1,2,3)
SyntaxError: starred assignment target must be in a list or tuple
It doesn't really make sense to use * in such situations anyway, you
can just do the normal `z = (1,2,3)`.
More information about the Python-list