久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么在使用 sum() 函數時會出現 'int' obj

Why does the #39;int#39; object is not callable error occur when using the sum() function?(為什么在使用 sum() 函數時會出現 int object is not callable 錯誤?)
本文介紹了為什么在使用 sum() 函數時會出現 'int' object is not callable 錯誤?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我試圖弄清楚為什么在范圍上使用 sum 函數時會出錯.

I'm trying to figure out why I'm getting an error when using the sum function on a range.

代碼如下:

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 total

這是錯誤:

line 8, in <module> total2 = sum(data3)
TypeError: 'int' object is not callable

我找到了這個錯誤的解釋:

I found this explanation for the error:

在 Python 中,可調用"通常是一個函數.該消息意味著您將數字(一個>int")視為一個函數(一個可調用"),所以Python不知道該做什么,所以它>停止.

In Python a "callable" is usually a function. The message means you are treating a number (an >"int") as if it were a function (a "callable"), so Python doesn't know what to do, so it >stops.

我還讀到 sum() 能夠用于列表,所以我想知道這里出了什么問題?

I've also read that sum() is capable of being used on lists, so I'm wondering what is going wrong here?

我剛剛在 IDLE 模塊中嘗試過,效果很好.但是,它在 python 解釋器中不起作用.有什么想法嗎?

I just tried it in an IDLE module and it worked fine. However, it doesn't work in the python interpreter. Any ideas on how that can be?

推薦答案

您可能將sum"函數重新定義為整數數據類型.所以它正確地告訴你整數不是你可以傳遞范圍的東西.

You probably redefined your "sum" function to be an integer data type. So it is rightly telling you that an integer is not something you can pass a range.

要解決此問題,請重新啟動您的解釋器.

To fix this, restart your interpreter.

Python 2.7.3 (default, Apr 20 2012, 22:44:07) 
[GCC 4.6.3] on linux2
Type "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 total
233168

如果你隱藏 sum 內置,你會得到你看到的錯誤

If you shadow the sum builtin, you can get the error you are seeing

>>> sum = 0
>>> total = sum(data3) # calculate sum of data3 list's elements
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

另外,請注意 sum 將在 set 上正常工作,無需將其轉換為 list

Also, note that sum will work fine on the set there is no need to convert it to a list

這篇關于為什么在使用 sum() 函數時會出現 'int' object is not callable 錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲欧洲成人av每日更新 | 国产精品一区二区久久 | 亚洲电影免费 | 国产高清在线精品 | 精品国产区 | 91porn成人精品 | 国产精品久久久av | 免费观看一级特黄欧美大片 | 成在线人视频免费视频 | 日韩视频在线免费观看 | 青草久久免费视频 | 日韩免费福利视频 | 久久久看| gogo肉体亚洲高清在线视 | 国产精品成av人在线视午夜片 | 日本激情一区二区 | 午夜一级做a爰片久久毛片 精品综合 | 亚洲精品aⅴ | 国产精品成人国产乱 | www.4hu影院 | 成人在线不卡 | 日韩一区二区视频 | 久久精品视频99 | 欧美一级小视频 | 亚洲资源站 | 欧美11一13sex性hd | 欧美精品在欧美一区二区 | 中文字幕一区二区三区日韩精品 | 国产精品电影在线观看 | 色婷婷久久久亚洲一区二区三区 | 亚洲国产成人久久综合一区,久久久国产99 | 成人高清视频在线观看 | 97国产精品视频人人做人人爱 | 精品免费av | 中文字幕在线网 | 国产精品一区二区免费看 | 色呦呦在线| 伊人激情网 | 日本中文在线视频 | 精品久久久久久亚洲综合网 | 亚洲精品视频在线观看视频 |