How to multiply all elements in a list in Python

2 Answers

0 votes
import math

lst = [3, 7, 8, 5, 1, 4]

result = math.prod(lst)

print(result)




'''
run:

3360

'''

 



answered Jul 10, 2022 by avibootz
0 votes
lst = [3, 7, 8, 5, 1, 4]

result = 1
for val in lst: 
    result = result * val

print(result)




'''
run:

3360

'''

 



answered Feb 26, 2023 by avibootz

Related questions

2 answers 209 views
2 answers 398 views
1 answer 204 views
1 answer 203 views
1 answer 327 views
...