sum() 方法对系列进行求和计算。
- sum(iterable[, start])
iterable:可迭代对象,如列表。
start:指定相加的参数,如果没有设置这个值,默认为 0。
- print(sum([0,1,2])) #无第二个参数,默认为0 3
- print(sum([0,1,2], 10)) # 元组计算总和后再加 10 13
- print(sum((0,1,2), 10)) # 列表计算总和后再加 10 13
转自 http://www.runoob.com/python/python-func-sum.html
来源: http://www.bubuko.com/infodetail-2431337.html