surya
0
Q:

python sum of array

#Python program to add all the array elements using the built-in function
lst = []
num = int(input("Enter the size of the array: "))
print("Enter array elements: ")
for n in range(num):
  numbers = int(input())
  lst.append(numbers)
print("Sum:", sum(lst))
2
>>> list = [1, 2, 3]
>>> sum(list)
6
11
# Python code to demonstrate the working of  
# sum() 
   
numbers = [1,2,3,4,5,1,4,5] 
  
# start parameter is not provided 
Sum = sum(numbers) 
print(Sum) 
  
# start = 10 
Sum = sum(numbers, 10) 
print(Sum) 
6

New to Communities?

Join the community