Sum of List Elements in Python
Calculate the sum of all elements in a list of numbers.
BeginnerList ProgramsExample 1 of 25
sum-of-list-elements.py
Run in browser1# Program to find sum of list elements23numbers = list(map(float, input("Enter numbers separated by space: ").split()))45print("Sum of elements:", sum(numbers))
Output
Enter numbers separated by space: 1 2 3 4 Sum of elements: 10.0
What's going on
We read space-separated numbers, convert them to float, and use the built-in sum() to add them.