Easy Tutorial
❮ Python String Replace Python Att Time Clock ❯

Python Calculate the Product of List Elements

Python3 Examples

Define a list of numbers and calculate the product of the list elements.

For example:

Input : list1 = [1, 2, 3] 
Output : 6 
Calculation: 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

Python3 Examples

❮ Python String Replace Python Att Time Clock ❯