TUTORIALProgrammingFETCHED
Python 计算列表元素之积
Python 计算列表元素之积 Python3 实例 定义一个数字列表,并计算列表元素之积。 例如: 输入 : list1 = [1, 2, 3] 输出 : 6 计算:1 * 2 * 3 实例 1 [mycode4 type='python'] def multiplyList(myList) : result = 1 for x in myList: ..
Updated 7/16/2026
Tutorial detail pages default to noindex.
Python 计算列表元素之积
定义一个数字列表,并计算列表元素之积。
例如:
输入 : list1 = [1, 2, 3] 输出 : 6 计算:1 * 2 * 3
实例 1
def multiplyList(myList) :
result = 1
for x in myList:
result = result * x
return result
list1 = [1, 2, 3]
list2 = [3, 2, 4]
print(multiplyList(list1))
print(multiplyList(list2))
result = 1
for x in myList:
result = result * x
return result
list1 = [1, 2, 3]
list2 = [3, 2, 4]
print(multiplyList(list1))
print(multiplyList(list2))
以上实例输出结果为:
6 24
Python3 实例