python

One line code to get the sum of a list in python

You can get the sum of items values that exist in a list using the sum() function of python. You can pass the list to the sum() method and it will return the sum of the all list items.

values = [1,2,3,4,5]

sum_of_values = sum(values)
print(sum_of_values)

# -> 15
Was this helpful?