您可能将“ sum”函数重新定义为整数数据类型。因此,它正确地告诉您,整数不能传递范围。
要解决此问题,请重新启动解释器。
Python 2.7.3 (default, Apr 20 2012, 22:44:07) [GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> data1 = range(0, 1000, 3)>>> data2 = range(0, 1000, 5)>>> data3 = list(set(data1 + data2)) # makes new list without duplicates>>> total = sum(data3) # calculate sum of data3 list's elements>>> print total233168
如果您隐藏了
sum内置函数,则会得到您看到的错误
>>> sum = 0>>> total = sum(data3) # calculate sum of data3 list's elementsTraceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: 'int' object is not callable
另外,请注意,该方法
sum可以很好地工作,
set无需将其转换为
list
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)