How to find sum a list of numbers in Python?

PythonServer Side ProgrammingProgramming

Python's built-in function sum() returns sum of numbers in an iterable object such as list or tuple. It takes two arguments, initial value which is optional and 0 by default and iterable object

Example

>>> l1=[10,20,30,40,50]
>>> ttl=sum(l1)
>>> ttl
150
>>> ttl=sum(range(10))
>>> ttl
45
raja
Published on 23-Feb-2018 10:40:44
Advertisements