fsum(n) # (m,e)
iterable_object : Iterable Object like list, set, tuple , range etc import math
print(math.fsum(range(0,10))) # 45.0
Example using list
import math
my_list=[1,2,3,4,5]
print(math.fsum(my_list)) # 15.0
Example using tuple
import math
my_tuple=(1.3,4.5,6.2,7.1)
print(math.fsum(my_tuple)) # 19.1
Example using using set
import math
my_set={1.3,4.5,6.2,7.1}
print(math.fsum(my_set))
We can use only iterable object
import math
my_data=5
print(math.fsum(my_data))
This will generate Error message
TypeError: 'int' object is not iterable
import math
print(type(math.fsum([4,6,1]))) # <class 'float'>
print(type(math.fsum([1.4,6,1]))) # <class 'float'>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.