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)

# -> 15
Was this helpful?