SubhanUllah Posted September 29, 2022 Report Posted September 29, 2022 If you mean multiplying all the list items by some common factor, list comprehension is quick and clean. It has the same for loop implication… li = [1, 2, 3, 4, 5] print([2*i for i in li]) #OUTPUT [2, 4, 6, 8, 10] If you rather mean multipling all the items together to get a product, you can still use a for loop such as… li = [1, 2, 3, 4, 5] total = 1 for i in li: total = total * i print(total) #OUTPUT 120 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.