The sum()
function is used to get the sum of the items in a given iterable such as list, tuples, sets e.tc. It takes one required positional argument i.e the iterable , and an optional argument, start
, which specifies the initial value, or the start value, for the sum.
sum(iterable, start = 0)
copy
start
defaults to 0 if not provided. If the iterable contains no items, it returns start.
The function iterates through the given iterable, and adds the value of each item to the total sum.
The function only works when the iterable
contains numerical data i.e integers, floats and complex.