fsum(iterable_object) returns the sum ( float data type ) of the elements of the iterable_object.
fsum(n) # (m,e) 
iterable_object : Iterable Object like list, set, tuple , range etc

Returns floating point number.

Example using range
import math
print(math.fsum(range(0,10))) # 45.0 
Example using list
import math
print(math.fsum(my_list)) # 15.0
Example using tuple
import math
print(math.fsum(my_tuple)) # 19.1
Example using using set
import math
We can use only iterable object
import math
This will generate Error message
 TypeError: 'int' object is not iterable

Data type of output

We will get float dtype out put by using fsum()
import math
print(type(math.fsum([4,6,1])))   # <class 'float'>
print(type(math.fsum([1.4,6,1]))) # <class 'float'>

Difference between fsum() and sum()

fsum() is included in Python math module so we have to import it before using. Where as sum() is part of built in functions of core Python so no need to import any library.

fsum() returns always float dtype. However sum() returns the same dtype of input number.
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer