Skip to content

Instantly share code, notes, and snippets.

@philpennock
Created August 28, 2012 23:38
Show Gist options
  • Save philpennock/3505352 to your computer and use it in GitHub Desktop.
Save philpennock/3505352 to your computer and use it in GitHub Desktop.
Demonstrate python function *args & **kwargs
>>> def foo(alpha, *args, **kwargs):
... print 'Foo called, alpha = %s' % repr(alpha)
... for a in args:
... print 'Arg: {%s}' % repr(a)
... for k, v in kwargs.iteritems():
... print 'Arg \"%s\" = \"%s\"' % (k, v)
...
>>> foo(234234, 'snert', 'wibble', 'bleurgh', fred=42, barney=-1)
Foo called, alpha = 234234
Arg: {'snert'}
Arg: {'wibble'}
Arg: {'bleurgh'}
Arg "barney" = "-1"
Arg "fred" = "42"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment