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

為什么在使用 sum() 函數(shù)時(shí)會(huì)出現(xiàn) 'int' obj

Why does the #39;int#39; object is not callable error occur when using the sum() function?(為什么在使用 sum() 函數(shù)時(shí)會(huì)出現(xiàn) int object is not callable 錯(cuò)誤?)
本文介紹了為什么在使用 sum() 函數(shù)時(shí)會(huì)出現(xiàn) 'int' object is not callable 錯(cuò)誤?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我試圖弄清楚為什么在范圍上使用 sum 函數(shù)時(shí)會(huì)出錯(cuò).

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

這是錯(cuò)誤:

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

我找到了這個(gè)錯(cuò)誤的解釋:

I found this explanation for the error:

在 Python 中,可調(diào)用"通常是一個(gè)函數(shù).該消息意味著您將數(shù)字(一個(gè)>int")視為一個(gè)函數(shù)(一個(gè)可調(diào)用"),所以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() 能夠用于列表,所以我想知道這里出了什么問(wèn)題?

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

我剛剛在 IDLE 模塊中嘗試過(guò),效果很好.但是,它在 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"函數(shù)重新定義為整數(shù)數(shù)據(jù)類(lèi)型.所以它正確地告訴你整數(shù)不是你可以傳遞范圍的東西.

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.

要解決此問(wèn)題,請(qǐng)重新啟動(dòng)您的解釋器.

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 內(nèi)置,你會(huì)得到你看到的錯(cuò)誤

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

另外,請(qǐng)注意 sum 將在 set 上正常工作,無(wú)需將其轉(zhuǎn)換為 list

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

這篇關(guān)于為什么在使用 sum() 函數(shù)時(shí)會(huì)出現(xiàn) 'int' object is not callable 錯(cuò)誤?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周?chē)L制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 日本精品视频 | 国产亚洲在线 | 男女激情av | 伊久久| 久操视频在线 | 成人免费看片&#39; | 日韩福利一区 | 综合网伊人 | 激情小说在线视频 | 三级网站视频 | 狠狠做深爱婷婷久久综合一区 | 国产精品一区二区在线 | 欧美色婷婷 | www.一区二区 | 色在线视频 | 欧美性猛交乱大交 | 亚洲视频在线观看 | 伊人网在线视频 | 亚洲国产免费 | 九九热视频在线观看 | 少妇视频网站 | 亚洲午夜在线 | 香蕉久久a毛片 | www.青青草.com | 日韩中文字幕第一页 | 91日本视频 | 日韩一区二区在线观看视频 | 黄色天天影视 | 国产成人精品亚洲 | 亚洲国产成人精品女人久久久 | 亚洲视频免费看 | 日本欧美久久久久免费播放网 | 欧美日韩一区二区在线 | 乳色吐息樱花 | 91综合网 | 天天爽夜夜操 | 日韩免费 | 久久99精品久久久久久 | 欧美一区二区三 | 日韩 欧美 亚洲 | 国产精品毛片久久久久久久 |