# How to multiply all elements in a list python?

1 vote
56 views

## Problem:

Recently I started learning python and just about to know more about list and tuple in python. I am a little bit known to the list and tuple and I can add or subtracts elements in a list. I wonder how to multiply all elements in a list python? I tried it in the adding process but it didn’t work for me. Is it doable?
Could anybody please show me the way to do it?

1 vote

## Solution:

Yes! Multiplication of all elements in a list of python is doable. You can multiply the elements in a couple of ways. I am trying to make it easier that you can understand the program real quick.

Method 1: Traversal

``````def multiList(numList) :
value = 1
for n in numList:
value = value * n
return value
list1 = [1, 2, 3]
list2 = [3, 4, 5]

print(multiList(list1))
print(multiList(list2)) ``````

Method 2: Using numpy.prod()

``````import numpy
list1 = [1, 2, 3]
list2 = [3, 4, 5]

value1 = numpy.prod(list1)
value2 = numpy.prod(list2)
print(value1)
print(value2) ``````

Both of the case will produce an output:

``````6
60``````

Thanks

## Related questions

1 vote
1 answer 14 views
14 views
Problem: Any clue how to slove this calculation? Multiply all values in a list python.
1 answer 51 views
51 views
Problem: How to I Solve this : can't multiply sequence by non-int of type 'list' HELP! I need help understanding this: can't multiply sequence by non-int of type 'list' Can someone please help solve this, I am new in python().
1 answer 4 views
4 views
Problem: Python number of elements in a list.
1 answer 9 views
9 views
Problem: Please solve it &hellip; Because I am unable to find out the solution .. How to add elements to list in python
1 answer 9 views
9 views
Problem: How can I list all the files in a directory in python and add them to a list?
1 answer 75 views
75 views
Problem : How to remove all occurrences of a value from a list? I tried in Python remove() will remove the first occurrence of value in a list. How to remove all occurences?
1 answer 6 views
6 views
Problem: How to remove all occurrences of a value from a list?