Python Compute the Product of List Elements
Define a list of numbers and compute the product of its elements.
For example:
输入 : list1 = [1, 2, 3]
输出 : 6
计算:1 * 2 * 3
Example 1
def
multiplyList
(
myList
)
:
result
=
1
for
x
in
myList:
result
=
result * x
return
result
list1
=
[
1
,
2
,
3
]
list2
=
[
3
,
2
,
4
]
(
multiplyList
(
list1
)
)
(
multiplyList
(
list2
)
)
The output of the above example is:
6
24
Python3 Examples