How to Sum Elements of a List

To calculate the sum of elements in a list, you can use the built-in function sum() in Python.

Example: Summing Elements in a List

# Summing elements in a list
numbers = [10, 20, 30, 40]
total = sum(numbers)
print(f"The total sum is {total}.")

Output

The total sum is 100.

Explanation: The sum() function adds up all the elements in the list and returns the total sum.