function that accepts any amount of arguments?

Ken ksterling at mindspring.com
Thu Apr 24 05:19:46 EDT 2008


"Steve Holden" <steve at holdenweb.com> wrote in message 
news:mailman.99.1209009225.12834.python-list at python.org...
> globalrev wrote:
>> if i want a function that can take any amount of arguments how do i
>> do?
>>
>> lets say i want a function average that accepts any number of integers
>> and returns the average.
>
> Use a parameter of the form *args - the asterisk tells the interpreter to 
> collect positional arguments into a tuple. Untested:
>
> def mean(*x):
>     total = 0.0
>     for v in x:
>         total += v
>     return v/len(x)
>

 think you want total/len(x) in return statement


> regards
>  Steve
> -- 
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/
> 





More information about the Python-list mailing list