Variable arguments to a Python function

Joe Cheng josephmcheng at hotmail.NO.SPAM.com
Thu May 29 07:00:52 EDT 2003


> import operator
> def product(*sequence):
>         return reduce(operator.mul, sequence)
>
> >>> product(1,2,3)
> 6

Nice!  And just for fun, without operator:

def product(*sequence):
    return reduce(lambda x, y: x*y, sequence)

I'm a noob to python (from Java, C#) and it's refreshing to see such concise
syntax...






More information about the Python-list mailing list