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 207 views
2 answers 395 views
1 answer 202 views
1 answer 201 views
1 answer 325 views
...