This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to calculate the sum of a list in Python.
Let’s say you have a list named ‘a’ with value [1, 2, 3, 4, 5].
a = [1, 2, 3, 4, 5]
In order to calculate the sum of a list, you can use the sum()
method.
a = [1, 2, 3, 4, 5]
print(sum(a))
# => 15
Note: The sum()
method functions by adding all items of an iterable and returning the result.
The post How to Calculate Sum of List in Python appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-23T10:27:30+00:00) How to Calculate Sum of List in Python. Retrieved from https://www.scien.cx/2021/02/23/how-to-calculate-sum-of-list-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.