[Tutor] Listing function arguments
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Sep 2 08:59:16 CEST 2004
> I wanted to know what the funciton uses for paramter names, so I can
assign
> values to variables of the same name and pass them to the function.
I'm still slightly confused about why you want to give the
variables the parameter *names*. You shouldn't need to give the
variables the same name as the parameters.
For example:
def f(x=0,y=1,z=2): return x+y+z
a = 3
b = 7
c = 42
print f(a,b,c) # -> 52
What is important is the type and sequence of the parameters.
The variables passed as arguments can have completely different
"names". There is a slight tweak with named parameters
where you have a many parameters and want to pass a subset
not necessarily in the order specified, and I guess that's what
you are trying to do?
> Anyway the tips given by Kent and Andrei are exactly what I wanted:
> help( myfunction )
And yes that would tell you the parameter names so that you can
assign the arguments by name, but you still don't need to name
your variables with the same names. Returning to our example:
print f(z=b)
we assign our variable b to the parameter named z.
HTH,
Alan G.
More information about the Tutor
mailing list