The syntax of sum() is:
sum(iterable, start)
The sum() function adds start and items of the given iterable from left to right.
The sum() function returns the sum of start and items of the given iterable.
numbers = [2.5, 3, 4, -5] # start parameter is not provided numbersSum = sum(numbers) print(numbersSum) # start = 10 numbersSum = sum(numbers, 10) print(numbersSum)
When you run the program, the output will be:
4.5 14.5
If you need to add floating point numbers with exact precision then, you should use math.fsum(iterable) instead
math.fsum(iterable)
If you need to concatenate items of the given iterable (items must be string), then you can use join() method.
''.join(sequence)
Visit this page to learn about, Python join() Method