altexpape
0
Q:

usage of sum() in python

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.
7
# 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
>>> list = [1, 2, 3]
>>> sum(list)
6
11

New to Communities?

Join the community