Write a Python program to find the sum of all elements in an array:-
l=[10,10,10,10,10]
sum=0
for i in l :
sum+=i
print(sum)
Output:-
50
It calculates the sum of all the elements in the list l
. The variable sum
is used to store the cumulative sum as you iterate through the elements of the list.
If you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).
HAPPY LEARNING !!!