温馨提示×

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

小亿
97
2023-10-31 13:33:31
栏目: 编程语言

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

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

0