The *,
indicates that this is the end of any positional arguments; all
arguments after this must be supplied by name i.e. the data
argument
must be supplied by name.
The **kwargs
gathers any other supplied names arguments into a
dictionary named kwargs
. This can be handy when you’re writing a
function which is mostly a wrapper for another function: you can collect
thearguments you care about, and pass through anything else to the
second function.
In the above definition the parameters y
, xmin
, xmax
, colors
,
linestyles
and label
can all be supplied by position. For example:
hlines(9, 0, 99, some_colours, 'dashed', 'label here')
would assign these values according to their position i.e. xmax
would
be 99
in the above.
Three of the positional values have defaults: colors
, linestyles
and
label
. You can leave any of these out. If you wanted to specify just
the label
, you might write:
hlines(9, 0, 99, label='label here')
This lets you supply that argument, but still skip colors
and
linestyles
. So you can supply the label
either by naming it or
by supplying enough positional parameters to reach the label
parameter.
By contrast, data
must be supplied by name because it comes after
the *,
in the parameter list.
You can also supply other named parameters, and they will land in
kwargs
.
So this:
hlines(9, 0, 99, label='label here', data=[1,2,3], extra=[5,6,7], something="foo")
would set:
y=9
xmin=0
xmax=99
colors=None
linestyles='solid'
label='label here'
data=[1,2,3]
kwargs={'extra':[5,6,7], 'something':'foo'}
Cheers,
Cameron Simpson cs@cskk.id.au