T
Thomas Philips
To compute the product of a list of numbers, I tried entering
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
reduce(__mul__,[1,2,3])
NameError: name '__mul__' is not defined
I can get the answer I want by defining a function that returns the
product of two numbers: return x*y
and then using it:
But why does my first approach not work? __mul__ is a valid method of
type int. Is there an obvious flaw in my logic?
Thomas Philips
reduce(__mul__,[1,2,3])
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
reduce(__mul__,[1,2,3])
NameError: name '__mul__' is not defined
I can get the answer I want by defining a function that returns the
product of two numbers: return x*y
and then using it:
6reduce(product,[1,2,3])
But why does my first approach not work? __mul__ is a valid method of
type int. Is there an obvious flaw in my logic?
Thomas Philips