如下所示:
# the basic way s = 0 for x in range(10): s += x # the right way s = sum(range(10)) # the basic way s = 1 for x in range(1, 10): s *= x # the other way from operator import mul reduce(mul, range(1, 10))
以上这篇在python中实现对list求和及求积就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。