Why can't you use varargs and keyword arguments together?

Jean-Paul Calderone exarkun at divmod.com
Thu Dec 21 17:59:50 EST 2006


On 21 Dec 2006 14:51:15 -0800, Sandra-24 <sandravandale at yahoo.com> wrote:
>I've always wondered why I can't do:
>
>def foo(a,b,c):
>    return a,b,c
>
>args = range(2)
>foo(*args, c = 2)
>
>When you can do:
>
>foo(*args, **{'c':2})

You just need to turn things around:

  >>> def foo(a, b, c):
  ...     return a, b, c
  ...
  >>> args = range(2)
  >>> foo(c=2, *args)
  (0, 1, 2)
  >>>

Jean-Paul



More information about the Python-list mailing list