📌  相关文章
📜  python 查找列表中所有元素的总和. - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:17.582000             🧑  作者: Mango

代码示例4
# Sum the contents of a list without the builtin sum function

list = [1,2,3,4,5]
sum = 0

# loop through each position of the list and 
# add the contents of each position to the variable, sum
for i in range(len(list)):
    sum += list[i]

# result is 1 + 2 + 3 + 4 + 5 = 15
print(sum)