How to Calculate Sum of List in Python
Posted on: February 23, 2021 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.
Share on social media
//