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
1# 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.
After this program
If the idea is still fuzzy, read Day 5: Lists and List Methods in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 list programs, or see every topic on Python exercises.