Find product of numbers in given list


Find product of numbers in list

To find the product of numbers in given list in Python, use a for loop to iterate over the elements of the list, and update the product using multiplication assignment operator.

The sample code to find the product of numbers in the list x is

product = 1
for num in x:
    product *= num

Examples

1. Find product of numbers in list x

In the following program, we take a list x, and find the product of numbers in the list x.

Python Program

x = [4, 5, 7, -1, 3]

product = 1
for num in x:
    product *= num

print(product)

Output

-420

Summary

In this tutorial of Python Examples, we learned how to find the product of numbers in given list using For Loop, with the help of well detailed examples.