function that accepts any amount of arguments?
Paul McNett
p at ulmcnett.com
Wed Apr 23 23:49:04 EDT 2008
globalrev wrote:
> if i want a function that can take any amount of arguments how do i
> do?
Put an asterisk before the argument name.
> lets say i want a function average that accepts any number of integers
> and returns the average.
def avg(*args):
return sum(args) / len(args)
There are some dangers (at least two glaring ones) with this code,
though, which I leave as an exercise for the reader.
:)
Paul
More information about the Python-list
mailing list