Python Calculate Product of List Elements

Document 对象参考手册Python3 Examples

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))

The output of the above example is:

6
24

Document 对象参考手册Python3 Examples

Other Extensions