描述:
sum()方法对序列进行求和计算
语法
sum(iterable【, start])
参数
iterable--可迭代对象,如:列表、元组、集合
start--指定相加的参数,如果没有设置这个值,默认为0
返回值
返回计算结果
示例代码:

ret = sum([2, 3, 5, 9]) # 求列表的总和 print(ret) ret2 = sum((5, 6, 4), 2) # 元组计算总和后再加2 print(ret2) ret3 = sum([9, 2, 1], 4) # 列表计算总和后再加4 print(ret3)