• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
November 09, 2022 |2.3K Views

Python program to multiply all numbers in the list

  Share  1 Like
Description
Discussion

MULTIPLY ALL NUMBERS IN A LIST

To multiply all the elements in a list, we take a well defined list consisting of integer/float only values from the user. As there is no in-built function to do this like sum, we can do it using multiple approaches, either by making it calculate or use methods from myriad libraries available.

Method 1: Using user defined functions

We take an array and pass/initialize it in the function, set a counter to 1 and keep on multiplying it with each element inside the iterable.

Method 2: Using NumPy library

NumPy offers a set of functions useful in performing mathematics in Python. It has a product method that we can use to store the product of the list

Method 3: Using Math library

Similar to NumPy, Math library also offers a product function which does exactly the same work as the NumPy library. However, the NumPy library can be to perform different operations and manipulations which the math library is not capable of.

Method 4: Using Reduce + mul

Reduce takes on an iterator as an argument and passes the mul function ( from operator library) also an argument to reduce the list of multiple elements into a single desired answer as product.

Python program to multiply numbers in a list:
https://www.geeksforgeeks.org/python-multiply-numbers-list-3-different-ways/