How to Sum all Values in a List or Tuple in Python using fsum() Function

fsum() function exists in Standard math Library of Python Programming Language. The purpose of this function is, to sum up, all the values in any iterable (tuples, lists) accurately.

Syntax of fsum() Function in Python

The syntax of fsum() function in Python is:
math.fsum( iterable )


fsum() Function Parameters

iterable – Lists and Tuples containing valid Python numbers as items.
Note: If items in iterable (tuples, lists) are not number, fsum() returns an TypeError.


Python fsum() Function Compatibility

Python 2.x – Yes
Python 3.x – Yes


fsum() Function Return Value

fsum() returns an accurate sum of any iterable as a floating point number.


Python fsum() Function Example

Output of Python fsum() function: