久久久久久久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)
主站蜘蛛池模板: av网站免费在线观看 | 欧美亚洲在线 | 91性高潮久久久久久久久 | 在线免费看黄网站 | 日韩免费毛片 | 久久不雅视频 | 精品一二区 | 中文字幕av一区二区三区谷原希美 | 欧美成人三级在线观看 | 三级福利视频 | 国产黄色在线播放 | 国产成人精品视频 | 91性视频 | 国产青青草 | 日韩欧美中文在线 | 中文av字幕 | 天天操天天干天天 | av黄色在线观看 | 成人网在线观看 | 日本精品久久 | 一级片大全 | 久久精品在线播放 | 日本亚洲精品 | www一级片| 蜜桃在线观看视频 | 亚洲第一av| 亚洲最新视频 | 在线观看欧美日韩视频 | 天天综合网站 | 在线一区视频 | 青娱乐av | 久久久久黄色 | 亚洲精品久久久久avwww潮水 | 欧美性猛交xxxx免费看久久久 | 午夜成人在线视频 | 国产精品一品二区三区的使用体验 | 色婷婷精品 | 亚洲精品911 | 五月婷婷深深爱 | 久久久夜 | 人人干人人澡 |