Python Calculate Product of List Elements
Define a list of numbers and calculate the product of the list 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]
print(multiplyList(list1))
print(multiplyList(list2))
result = 1
for x in myList:
result = result * x
return result
list1 = [1, 2, 3]
list2 = [3, 2, 4]
print(multiplyList(list1))
print(multiplyList(list2))
The output of the above example is:
6 24Other Extensions
Python3 Examples