How to find sum a list of numbers in Python?


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

Updated on: 21-Feb-2020

105 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements