0
Q:

python sum of list

# 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) # result is 25  
# start = 10 
Sum = sum(numbers, 10) 
print(Sum) # result is 10 +25 = 35
12
>>> list = [1, 2, 3]
>>> sum(list)
6
11
def sum_list(array):
    summation = 0
    for x in range(0, len(array)):
        summation += array[x]
    return summation
3
# 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
sum(iterable, start)  

iterable : iterable can be anything list , tuples or dictionaries, but most importantly it should be numbers.
start : this start is added to the sum of numbers in the iterable. 

If start is not given in the syntax , it is assumed to be 0.
2
b = [1,2,3]
a = sum(b)
# 6
0

New to Communities?

Join the community