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

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

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

問題描述

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

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

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"函數(shù)重新定義為整數(shù)數(shù)據(jù)類型.所以它正確地告訴你整數(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.

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

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)置,你會得到你看到的錯誤

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 上正常工作,無需將其轉(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ù)時會出現(xiàn) 'int' object is not callable 錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
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(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 日韩欧美一级片 | 91亚洲国产成人久久精品网站 | 成人免费视频在线观看 | 国内精品久久影院 | 日韩 欧美 综合 | 97人人澡人人爽91综合色 | 国产伦精品一区二区三区精品视频 | 久久se精品一区精品二区 | 国产精品久久av | 高清国产一区二区 | 罗宾被扒开腿做同人网站 | 久久精品国产一区二区三区 | 91精品国产91久久综合桃花 | 日p视频免费看 | 五月婷婷在线视频 | 91精品国产色综合久久不卡蜜臀 | 全部免费毛片在线播放网站 | 久久久无码精品亚洲日韩按摩 | 国产欧美在线视频 | 日韩电影中文字幕 | 美女张开腿露出尿口 | 91精品国产91久久久久游泳池 | 免费亚洲视频 | 亚洲一区二区久久久 | 日日日视频 | 伊人春色成人网 | 久久久精品综合 | 欧美日韩免费 | 亚洲欧美日韩精品久久亚洲区 | 欧美日韩在线精品 | 欧美日韩一区二区在线观看 | 国产欧美在线观看 | 久久国产精品首页 | 激情小说综合网 | 亚洲一区 中文字幕 | 97色在线观看免费视频 | 久久久中文 | 在线视频亚洲 | 91精品国产91久久久久久最新 | 看一级黄色毛片 | 国产精品欧美一区二区 |