Python 列表元素乘积计算示例
# 定义一个包含四个数字的列表
numbers = [2, 4, 6, 8]
# 定义一个变量用来保存乘积,初始值为1
product = 1
# 遍历列表中的每个元素
for number in numbers:
# 将当前元素乘以 product 并更新 product 的值
product = product * number
# 输出最终的乘积结果
print('The product is:', product)
The product is: 384
原文地址: https://www.cveoy.top/t/topic/nOXK 著作权归作者所有。请勿转载和采集!