Sum of List Elements

Tags: Lists, Looping

Given a list of integers, write a Python function to find and return the sum of all elements in the list.

Example 1:
Input: [1,2,3,4,5]
Output: 15
Example 2:
Input: [10,20,30,40,50]
Output: 150

You can use a looping structure to iterate through each element of the list and add it to a variable.

def sum_list(numbers):
    return sum(numbers)

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!