fsum() finds the sum between a given range or an iterable. It needs the import of the math library. Its widely used in mathematical calculations.
Syntax
Below is the syntax of the function.
maths.fsum( iterable ) The iterable can be a range, array , list. Return Type : It returns a floating point number.
Below are the example on how fsum function on a single number or on group of elements in a list.
Example
import math # Using range print(math.fsum(range(12))) # List of Integers listA = [5, 12, 11] print(math.fsum(listA)) # List of Floating point numbers listB = [9.35, 6.7, 3] print(math.fsum(listB))
Output
Running the above code gives us the following result −
66.0 28.0 19.05