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

帶有列表參數的 Python sum() 函數

Python sum() function with list parameter(帶有列表參數的 Python sum() 函數)
本文介紹了帶有列表參數的 Python sum() 函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要使用 sum() 函數來對列表中的值求和.請注意,這與使用 for 循環手動添加數字不同.我以為它會像下面這樣簡單,但我收到 TypeError: 'int' object is not callable.

I am required to use the sum() function in order to sum the values in a list. Please note that this is DISTINCT from using a for loop to add the numbers manually. I thought it would be something simple like the following, but I receive TypeError: 'int' object is not callable.

numbers = [1, 2, 3]
numsum = (sum(numbers))
print(numsum)

我查看了一些其他解決方案,這些解決方案涉及設置 start 參數、定義地圖或在 sum() 中包含 for 語法,但我沒有這些變化的任何運氣,并且無法弄清楚發生了什么.有人可以為我提供最簡單的 sum() 示例,該示例將匯總一個列表,并解釋為什么它會以這種方式完成?

I looked at a few other solutions that involved setting the start parameter, defining a map, or including for syntax within sum(), but I haven't had any luck with these variations, and can't figure out what's going on. Could someone provide me with the simplest possible example of sum() that will sum a list, and provide an explanation for why it is done the way it is?

推薦答案

你在其他地方使用過變量 sum 嗎?這樣就可以解釋了.

Have you used the variable sum anywhere else? That would explain it.

>>> sum = 1
>>> numbers = [1, 2, 3]
>>> numsum = (sum(numbers))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

sum 這個名字現在不再指向函數,它指向一個整數.

The name sum doesn't point to the function anymore now, it points to an integer.

解決方案:不要將變量稱為 sum,將其稱為 total 或類似的名稱.

Solution: Don't call your variable sum, call it total or something similar.

這篇關于帶有列表參數的 Python sum() 函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Sum values in a dict of lists(列表字典中的總和值)
How to sum numbers from a text file in Python(如何在 Python 中對文本文件中的數字求和)
What is a subtraction function that is similar to sum() for subtracting items in list?(什么是類似于 sum() 的減法函數,用于減去列表中的項目?)
Python equivalent of sum() using xor()(Python 等價于 sum() 使用 xor())
sum matrix columns in python(python中的求和矩陣列)
sum of N lists element-wise python(N個列表元素的總和python)
主站蜘蛛池模板: 天天天天天操 | 一本色道精品久久一区二区三区 | 欧美一区2区三区4区公司二百 | 精品久久香蕉国产线看观看亚洲 | 欧美激情一区二区 | 亚洲天堂一区二区 | 亚洲一区二区三区在线视频 | 午夜极品| 精品99在线 | 欧洲精品一区 | 欧美成人一区二免费视频软件 | 天天在线操 | 一区在线视频 | 午夜视频在线 | 97中文视频 | 国产不卡一区 | www.久草.com | 久久99蜜桃综合影院免费观看 | 欧美日韩在线一区二区 | 91av在线免费看 | 国产精品18hdxxxⅹ在线 | 欧美亚洲国产一区 | 免费在线黄 | 亚洲久草 | 中文字幕在线一区 | 一级黄色片美国 | 亚洲成人久久久 | 久久久久国产精品一区二区 | 中文区中文字幕免费看 | 男人的天堂亚洲 | 欧美一区二区免费电影 | 九九精品在线 | 91精品久久久久久久久中文字幕 | 国产精品久久久久久久久久软件 | 亚洲精品欧美精品 | .国产精品成人自产拍在线观看6 | 亚洲区一区二区 | 亚洲久草| 91精品国产综合久久精品 | 精品一区二区三区视频在线观看 | 久久99精品久久久久久狂牛 |