[Tutor] Modify inherited methods
Eike Welk
eike.welk at gmx.net
Wed Apr 28 22:51:00 CEST 2010
On Wednesday April 28 2010 20:57:27 C M Caine wrote:
> Thank you all. One tangentially related question: what does (self,
> *args, **kwargs) actually mean? How does one reference variables given
> to a function that accepts these inputs?
*args is a tuple containing the positional arguments;
**kwargs is a dictionary which contains the keyword arguments.
The stars before the variable names are the special syntax to handle arbitrary
function arguments; you can use any variable names you want. You can use the
syntax in a function call and in a function definition.
Here's an example session with Ipython:
In [5]: def foo(*args, **kwargs):
...: print "args: ", args
...: print "kwargs: ", kwargs
...:
...:
In [6]: foo(1, 2, 3)
args: (1, 2, 3)
kwargs: {}
In [7]: foo(1, 2, 3, a=4, b=5)
args: (1, 2, 3)
kwargs: {'a': 4, 'b': 5}
In [8]: foo( *(10, 11), **{"p":20, "q":21})
args: (10, 11)
kwargs: {'q': 21, 'p': 20}
Eike.
More information about the Tutor
mailing list