Variable arguments to a Python function
Andrew Bennetts
andrew-pythonlist at puzzling.org
Thu May 29 00:36:48 EDT 2003
On Thu, May 29, 2003 at 12:22:11AM -0400, Mahboob wrote:
> How can I pass variable number of arguments to a Python function and access
> them inside the function?
>
> In Perl, you could write
>
> sub all_of {
> my $result = 1;
> while ( @_) {
> $result *= shift;
> }
> return result;
> }
Translated to Python:
def all_of(*args):
result = 1
for arg in args:
result *= arg
return result
-Andrew.
More information about the Python-list
mailing list