📜  对列表的内容求和 python 代码示例

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

代码示例1
# 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)