Skip to content

Instantly share code, notes, and snippets.

@notmyname
Created February 13, 2013 18:33
Show Gist options
  • Save notmyname/4946922 to your computer and use it in GitHub Desktop.
Save notmyname/4946922 to your computer and use it in GitHub Desktop.
how 2 python?
def foo(x, y=None, *a, **kw):
print '%r, %r, %r, %r' % (x, y, a, kw)
foo(1)
foo(1, 2)
foo(1, 2, 3, 4, 5, bar=6)
foo(1, 2, y=3) # want: 1, 3, (2,), {}
@pyKun
Copy link

pyKun commented May 7, 2013

In python, 'def foo(1, y=2, 3, 4, bar=5)' is not allowed. So if you need the key 'y' especially, could use like this:
def foo(x, _a, *_kw):
...
y = kw.pop('y', 'default value')
...

I found this is old issue 3 months ago. Do you found your best answer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment