Home >>Python math Module >Python math.fsum() Method

Python math.fsum() Method

Python math.fsum() Method

Python math.fsum() method in python is used to returns sum in float of all values and , it accepts an iterable object like tuple, lists, arrays, etc (that should contain numbers in either integers or floats) as a floating point number.

Syntax:
math.fsum(iterable)

Parameter Values

Parameter Description
Iterable It is required a number to return floats of values
Here is an Example of Python math.fsum() Method:

import math
x = (2, 4, 6, 8, 10)
print(math.fsum(x))

Output:
30.0
Example 2:

import math
v = range(10)  
w = [5, 10, 15, 20, 25]   
x = [5.05, 10, 15.06, 20, 25.07]  
y = [5.25, 20.15]  
z = (5, 14, 10.03, 25.05) 
print("fsum(v): ", math.fsum(v))
print("fsum(w): ", math.fsum(w))
print("fsum(x): ", math.fsum(x))
print("fsum(y): ", math.fsum(y))
print("fsum(z): ", math.fsum(z))

Output:
fsum(v): 45.0
fsum(w): 75.0
fsum(x): 75.18
fsum(y): 25.4
fsum(z): 54.08

No Sidebar ads