首页 > 文章列表 > Python中对数组求和的方法有哪些?

Python中对数组求和的方法有哪些?

Python 精选
234 2024-03-03

python对数组求和的方法是什么

python中可以使用内置函数`sum()`对数组求和。该函数接受一个可迭代对象作为参数,并返回其元素的和。

示例:
```Python
arr = [1, 2, 3, 4, 5]
total = sum(arr)
print(total)  # 输出:15
```