46 reduce function in python

 '''

1. reduce is used to do operation on each iterable value and 

its return all operations result sum.

2. reduce takes two parameters one is function another one is iterable object


'''


from functools import reduce


#(1+2)+3)+4)+5)




#fact = reduce(lambda a,b: a * b,[1,2,3,4,5])


fib = reduce(lambda a,b: a + b,[1,2,3,4,5])

print(fib)




Comments

Popular posts from this blog

19 sys module in python

32 constructor in python

1 PYTHON PROGRAMMING