from collections import Iterable
def mysum(list):
count = 0
if isinstance(list, Iterable):
for i in list:
if type(i) == int or type(i) == float:
count += i
else:
return "unsupported operand type(s) for +: 'int' and '%s'" %type(i)
return count
else:
print("% s 不可迭代" % type(list))
import random numlist = [random.randint(1,100) for i in range(100)] reduce(lambda x,y:x+y, numlist)